Java实现数字转换为人民币大写.doc_第1页
Java实现数字转换为人民币大写.doc_第2页
Java实现数字转换为人民币大写.doc_第3页
Java实现数字转换为人民币大写.doc_第4页
Java实现数字转换为人民币大写.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Java实现数字转换为人民币大写四种简单方法/输入一个数字,将它按人民币大写输出package com.bluedot;public class Da2 public static void main(String args) /改变money的值, 不超过9位数。int money = 100100;int length = 0;char a = 零, 一, 二, 三, 四, 五, 六, 七, 八, 九 ;char b = 一, 十, 百, 千, 万, 十, 百, 千, 亿, 十 ;int c = new int10;System.out.println(money + 元);while (money 0) clength = money % 10;/System.out.print( 第 + length + 位:);/System.out.println(clength);money /= 10;length+;/ 位数对照 一, 十, 百, 千, 万, 十, 百, 千, 亿, 十/ n: 0 1 2 3 4 5 6 7 8 9int n = length - 1;/System.out.println(n);int wanwei = 0; / 记录万位数是否都为零。while (n 0) if (n 3 & n 0) / 个位不为零,输出数int j = cn;System.out.print(aj);System.out.print(元整);package com.bluedot;public class Rmb public static String method2(int n) if(n=0)return零; if(n=1)return壹; if(n=2)return贰; if(n=3)return叁; if(n=4)return肆; if(n=5)return伍; if(n=6)return陆; if(n=7)return柒; if(n=8)return捌; if(n=9)return玖; return ; public static void method(int a) int b=a/1000; int b1=a%1000/100; int b2=a%100/10; int b3=a%10; String str=method2(b)+仟+method2(b1)+佰+method2(b2)+拾+method2(b3)+元; System.out.print(str); public static void main(String args)int a=1234;method(a);package com.bluedot;public class Daxie public static String bijiao(int n) /改进老师的方法,能输出0到十万之内的任意数,不会出错!if (n = 0)return 零;if (n = 1)return 壹;if (n = 2)return 贰;if (n = 3)return 叁;if (n = 4)return 肆;if (n = 5)return 伍;if (n = 6)return 陆;if (n = 7)return 柒;if (n = 8)return 捌;if (n = 9)return 玖;return ;public static void weishu(int n) int a = n / 10000;/ 万位int a1 = n / 1000 % 10;/ 千位int a2 = n / 100 % 10;/ 百位int a3 = n / 10 % 10;/ 十位int a4 = n % 10;String str = bijiao(a) + 万 + bijiao(a1) + 仟 + bijiao(a2) + 佰+ bijiao(a3) + 拾 + bijiao(a4) + 圆;str = str.replace(零万零仟零佰零圆, 圆);str = str.replace(零万零仟零佰零拾, );str = str.replace(零万零仟零佰, );str = str.replace(零万零仟, );str = str.replace(零万, );if(a = n / 10000)!=0)/万位不为零str = str.replace(零仟零佰零拾零圆, 圆);str = str.replace(零仟零佰零拾, 零);str = str.replace(零仟零佰, 零);str = str.replace(零仟, 零);if(n / 1000 % 10)!=0)/ 千位不为零str = str.replace(零佰零拾零圆, 圆);str = str.replace(零佰零拾, 零);str = str.replace(零佰, 零);str = str.replace(零佰, 零);if(a2 = n / 100 % 10)!=0)/ 百位不为零str = str.replace(零佰零拾, 零);str = str.replace(零拾零圆, 圆);if(n / 10 % 10)!=0)/ 十位不为零str = str.replace(零圆, 圆);for (int k = 0; k = 100000) System.out.print(对不起,拾万圆以上超出计算范围!); elseweishu(n);package com.bluedot;public class Daxie public static String bijiao(int n) /改进老师的方法,能输出0到十万之内的任意数,不会出错!if (n = 0)return 零;if (n = 1)return 壹;if (n = 2)return 贰;if (n = 3)return 叁;if (n = 4)return 肆;if (n = 5)return 伍;if (n = 6)return 陆;if (n = 7)return 柒;if (n = 8)return 捌;if (n = 9)return 玖;return ;public static void weishu(int n) int a = n / 10000;/ 万位int a1 = n / 1000 % 10;/ 千位int a2 = n / 100 % 10;/ 百位int a3 = n / 10 % 10;/ 十位int a4 = n % 10;String str = bijiao(a) + 万 + bijiao(a1) + 仟 + bijiao(a2) + 佰+ bijiao(a3) + 拾 + bijiao(a4) + 圆;str = str.replace(零万零仟零佰零圆, 圆);str = str.replace(零万零仟零佰零拾, );str = str.replace(零万零仟零佰, );str = str.replace(零万零仟, );str = str.replace(零万, );if(a = n / 10000)!=0)/万位不为零str = str.replace(零仟零佰零拾零圆, 圆);str = str.replace(零仟零佰零拾, 零);str = str.replace(零仟零佰, 零);str = str.replace(零仟, 零);if(n / 1000 % 10)!=0)/ 千位不为零str = str.replace(零佰零拾零圆, 圆);str = str.replace(零佰零拾, 零);str = str.replace(零佰, 零);str = str.replace(零佰, 零);if(a2 = n / 100 % 10)!=0)/ 百位不为零str = str.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论