----------------------ASP.Net+Unity开发、.Net培训、期待与您交流! ----------------------
题目:要求用户输入一个小于等于9999的正整数,要求输出其汉字读法。
比如用户输入1024,则输出“一万零二十四”,如果用户输入“123”则输出“一百二十三”。
package com.heima.java_Demo;
import java.util.Scanner;
/*用户输入1024,则输出“一万零二十四”,如果用户输入“123”则输出“一百二十三
* 例如:用戶輸入118
* 用戶輸入,分析輸入的百位、十位、個位、分別是多少
*/
public class Demo10 {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.println("尊敬的用户请输入:");
int in=input.nextInt();
int q=0,b=0,s=0,g=0;
q=in/1000%10;//千位
b=in/100%10;//百位
s=in/10%10;//十位
g=in%10;//個位
//千位判断
if(!(q<0)){
if(q==0){
if(in<4){
System.out.print("零");
}
System.out.print("");
}else{
Swtich(q);
System.out.print("千");
}
//百位判断
if(!(b<0)){
if(b==0){
if(in<3){
System.out.print("零");
}else{
System.out.print("");
}
}else{
Swtich(b);
System.out.print("佰");
}
}
//十位判断
if(!(s<0)){
if(s==0){
if(in<2){
System.out.print("零");
}
else{
System.out.print("");
}
}else{
Swtich(s);
System.out.print("十");
}
}
//个位判断
if(!(g<0)){
if(g==0){
System.out.print("");
}else{
Swtich(g);
}
}
}
}
public static void Swtich(int i){
switch(i){
case 0:System.out.print("零");break;
case 1:System.out.print("壹");break;
case 2:System.out.print("兩");break;
case 3:System.out.print("三");break;
case 4:System.out.print("肆");break;
case 5:System.out.print("伍");break;
case 6:System.out.print("六");break;
case 7:System.out.print("七");break;
case 8:System.out.print("八");break;
case 9:System.out.print("九");break;
}
}
}
<span style="font-family: Arial; font-size: 13.63636302947998px; line-height: 25.99431800842285px;"><span style="font-size: 18px;"><span style="font-size: 14px;"><span style="font-weight: bold;"><span style="font-size: 18px;"><span style="font-weight: bold;"><span style="font-size: 18px;"><span style="font-size: 14px;"><span style="font-size: 12px;">----------------------<a target=_blank target="_blank" href="http://www.itheima.com/" style="color: rgb(202, 0, 0); text-decoration: none;">ASP.Net+Unity开发</a>、<a target=_blank target="_blank" href="http://www.itheima.com/" style="color: rgb(202, 0, 0); text-decoration: none;">.Net培训</a>、期待与您交流! ----------------------</span></span></span></span></span></span></span></span></span>