匿名用户
1级
2018-08-23 回答
看了这个简单的代码,你应该就懂了
package cn.txet.partice;
import java.util.Scanner;
public class DemoBigNumbers {
int a, b, c;
String bi, si, ge;
public static void main(String[] args) {
DemoBigNumbers db = new DemoBigNumbers();
System.out.println("请输入一个三位数");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();//获取键盘输入的三位数
db.exchange(num);//调用下面的方法
}
public void exchange(int num) {
//使用这个方法,把一个三位数,分解成百位,十位,个位,
if (num / 100 > 0 && num / 100 <=9) {
a = num / 100;
//百位:用switch选择百位字符串
switch (a) {
case 1:
bi = "一百";
break;
case 2:
bi = "二百";
break;
case 3:
bi = "三百";
break;
case 4:
bi = "四百";
break;
case 5:
bi = "五百";
break;
case 6:
bi = "六百";
break;
case 7:
bi = "七百";
break;
case 8:
bi = "八百";
break;
case 9:
bi = "九百";
break;
}
if (num / 10 >= 10 && num / 10 <= 99) {
int s = num / 10;
b = s % (a * 10);
//十位,也是用switch选择十位字符串
switch (b) {
case 0:
si="零";
break;
case 1:
si = "一十";
break;
case 2:
si = "二十";
break;
case 3:
si = "三十";
break;
case 4:
si = "四十";
break;
case 5:
si = "五十";
break;
case 6:
si = "六十";
break;
case 7:
si = "七十";
break;
case 8:
si = "八十";
break;
case 9:
si = "九十";
break;
}
}
if(num%(a*100+b*10)>=0&&num%(a*100+b*10)<=9)
//把个位数从num,三位数字当中分离出来
c=num%(a*100+b*10);
个位:用switch选择个位字符串
switch(c) {
case 0:
ge="零";
break;
case 1:
ge="一";
break;
case 2:
ge="二";
break;
case 3:
ge="三";
break;
case 4:
ge="四";
break;
case 5:
ge="五";
break;
case 6:
ge="六";
break;
case 7:
ge="七";
break;
case 8:
ge="八";
break;
case 9:
ge="九";
break;
}
System.out.println("您输入的数为: "+bi+si+ge);
} else {
System.out.println("请输入三位数");
}
}
}
追问:
我按照这个代码打完输出的还是原来的数字
追问:
为啥啊
追问: