问题:输入一个正整数数(1<m<100000),把这个正整数的倒着输出,中间用空格隔开。问各位数字中恰好含有 几个 3。
分析:
- 先确定m的位数,用while循环
- 再用for循环遍历到每一位(对10取余可得个位数,除10可得十位)
- 问恰好有几个3,用if判断
代码:
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = m;//m的值
int count = 1,i,t,r=0;
//判断m的位数
while(m>=10) {
m = m/10;
count++;//count是m的位数
}
System.out.println("m是"+count+"位数");
//循环变量m的每位数
for(i=1;i<=count;i++) {
t = n%10;
n = n/10;
//判断有几个三
if(t ==