import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class shuzhi {
public static void main(String args[]) throws IOException {
int g, n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0, n8 = 0, n9 = 0, n0 = 0;
System.out.println("请输入一个16位数字:");
//x=(int)System.in.read();
//x=Integer.parseInt(args[0]);
BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
long x = Long.parseLong(bin.readLine());//16位的应该用long
//x=(int)bin.readLine( );
//x=Long.parseLong(bin.readLine( ));
do {
g = (int)(x % 10);//这里要做类型转换
switch (g) {
case 9:
n9++;
break;
case 8:
n8++;
break;
case 7:
n7++;
break;
case 6:
n6++;
break;
case 5:
n5++;
break;
case 4:
n4++;
break;
case 3:
n3++;
break;
case 2:
n2++;
break;
case 1:
n1++;
break;
case 0:
n0++;
break;
}
} while ((x = x / 10) > 0);//这里的判断不对,应该大于0
System.out.println(n0 + n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8 + n9);
}
}
这种问题不会有人回答的…求给分啦,谢
int类型?16位就溢出了。应该使用long或者double类型,不过相应语句要变一变,而且switch也要换换,使用if写吧。
刚才调试了一下!!
16位的不能用int
用long把
还有do {} while;
后面while的条件应该是这样
while((x=x/10) > 0);