数字换大写的java 应用程序―――有趣之问十
1、从键盘输入任意数字, 例如:10860,然后输出其相对应的大写, 如: 壹万〇捌佰陆拾圆整. 请编写一个JAVA 应用程序实现它(提示:参考如下图。)
//////////////////////////////////////////////////
import java.util.Scanner;
/**
* 键盘输入任意数字, 例如:10860,然后输出其相对应的大写, 如: 壹万〇捌佰陆拾圆整. */
public class ChangeNumberTest {
public static void main(String[] args) { String[] shuzi = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; String[] weishu = { "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", " 拾", "佰", "仟" , "兆"}; Scanner sc = new Scanner(System.in); System.out.println("本程序是:将一个13位以下的整数金额转换成大写汉字金额表示形式。System.out.print("请输入数据:"); String ss = sc.next(); //"15012" ===>>> '1' '5' '0' '1' '2' int len = ss.length(); String result = ""; //n 表示这个整数的长度 for ( int i = 0; i
int x = ss.charAt(i) - '0'; int loc = len-i-1; String s1 = shuzi[x]; \n\n");
} } } String d1 = weishu[loc]; if( x == 0 ){ } if( loc == 4 || loc == 8 ){ } result += s1 + d1 ; result += d1; //当数字为零时且是万位或亿位时。 result += s1; }else{ }else{ result += "圆整"; //连续的多个零变为一个零 while(result.indexOf("零零") != -1){ } if( result.indexOf("零万")!=-1 ){ } if( result.indexOf("零亿")!=-1 ){ } if( result.indexOf("零圆")!=-1 ){ } if( result.indexOf("亿万")!=-1 ){ } System.out.print("\n你 输 入 的 数 字 是>>>"); System.err.println(ss); System.out.print("以上数对应大写数字为>>>"); System.err.println( result ); result = result.replace("亿万", "亿"); result = result.replace("零圆", "圆"); result = result.replace("零亿", "亿"); result = result.replace("零万", "万"); result = result.replace("零零", "零");
/////////////////////////////////////////////////
import java.util.Scanner;
/**
* 键盘输入任意数字, 例如:10860,然后输出其相对应的大写, 如: 壹万〇捌佰陆拾圆整. */
public class ChangeTest {
String[] shuzi = { " 零" , " 壹" , " 贰" , " 叁" , " 肆" , " 伍" , " 陆" , " 柒" , " 捌" , " String[] weishu = { "" , " 拾" , " 佰" , " 仟" , " 万" , " 拾" , " 佰" , " 仟" , " 亿" , " 拾" , " 佰" , " 仟" }; Scanner sc = new Scanner(System.in ); System. out .println(" 请输入数据:"); String ss = sc.nextLine(); //int x = Integer.parseInt(ss); //long x = Long.parseLong(ss); char [] ch = ss.toCharArray(); StringBuilder vs = new StringBuilder(); //n 表示这个整数的长度 for (int i = 0, n = ss.length(); i
} } } } break ; vs.append(" 圆整" ); System. out .print("\n你 输 入 的 数 字 是>>>"); System. err .println(ss); try { } System. out .print(" 以上数对应大写数字为>>>"); System. err .println(vs); Thread. sleep (300); } catch (InterruptedException e) {
/////////////////////////////////////////////////
数字换大写的java 应用程序―――有趣之问十
1、从键盘输入任意数字, 例如:10860,然后输出其相对应的大写, 如: 壹万〇捌佰陆拾圆整. 请编写一个JAVA 应用程序实现它(提示:参考如下图。)
//////////////////////////////////////////////////
import java.util.Scanner;
/**
* 键盘输入任意数字, 例如:10860,然后输出其相对应的大写, 如: 壹万〇捌佰陆拾圆整. */
public class ChangeNumberTest {
public static void main(String[] args) { String[] shuzi = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; String[] weishu = { "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", " 拾", "佰", "仟" , "兆"}; Scanner sc = new Scanner(System.in); System.out.println("本程序是:将一个13位以下的整数金额转换成大写汉字金额表示形式。System.out.print("请输入数据:"); String ss = sc.next(); //"15012" ===>>> '1' '5' '0' '1' '2' int len = ss.length(); String result = ""; //n 表示这个整数的长度 for ( int i = 0; i
int x = ss.charAt(i) - '0'; int loc = len-i-1; String s1 = shuzi[x]; \n\n");
} } } String d1 = weishu[loc]; if( x == 0 ){ } if( loc == 4 || loc == 8 ){ } result += s1 + d1 ; result += d1; //当数字为零时且是万位或亿位时。 result += s1; }else{ }else{ result += "圆整"; //连续的多个零变为一个零 while(result.indexOf("零零") != -1){ } if( result.indexOf("零万")!=-1 ){ } if( result.indexOf("零亿")!=-1 ){ } if( result.indexOf("零圆")!=-1 ){ } if( result.indexOf("亿万")!=-1 ){ } System.out.print("\n你 输 入 的 数 字 是>>>"); System.err.println(ss); System.out.print("以上数对应大写数字为>>>"); System.err.println( result ); result = result.replace("亿万", "亿"); result = result.replace("零圆", "圆"); result = result.replace("零亿", "亿"); result = result.replace("零万", "万"); result = result.replace("零零", "零");
/////////////////////////////////////////////////
import java.util.Scanner;
/**
* 键盘输入任意数字, 例如:10860,然后输出其相对应的大写, 如: 壹万〇捌佰陆拾圆整. */
public class ChangeTest {
String[] shuzi = { " 零" , " 壹" , " 贰" , " 叁" , " 肆" , " 伍" , " 陆" , " 柒" , " 捌" , " String[] weishu = { "" , " 拾" , " 佰" , " 仟" , " 万" , " 拾" , " 佰" , " 仟" , " 亿" , " 拾" , " 佰" , " 仟" }; Scanner sc = new Scanner(System.in ); System. out .println(" 请输入数据:"); String ss = sc.nextLine(); //int x = Integer.parseInt(ss); //long x = Long.parseLong(ss); char [] ch = ss.toCharArray(); StringBuilder vs = new StringBuilder(); //n 表示这个整数的长度 for (int i = 0, n = ss.length(); i
} } } } break ; vs.append(" 圆整" ); System. out .print("\n你 输 入 的 数 字 是>>>"); System. err .println(ss); try { } System. out .print(" 以上数对应大写数字为>>>"); System. err .println(vs); Thread. sleep (300); } catch (InterruptedException e) {
/////////////////////////////////////////////////