请问我这个程序有什么错误吗?
int num =999; int count = 0; for(;num>0;) { num=num/10; count+=1; if(count>10) { break; } } System.out.println("它是个"+count+"位数");
int num =999; int count = 0; for(;num>0;) { num=num/10; count+=1; if(count>10) { break; } } System.out.println("它是个"+count+"位数");
2017-04-08
楼主可以这样写,你可以看看:
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
System.out.println("请输入一个整数: ");
int num = sca.nextInt();
int count = 0;
while (num > 0) {
num = num / 10;
count += 1;
}
System.out.println("您输入了一个 " + count + " 位数");
if (count > 10) {
System.out.println("输入错误");
}
}
}
举报