如何在我这个代码中加入判定小于10位
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
do{num=num/10;count++;}while(num>1);
System.out.println("它是个" + count + "位的数!");
}
}
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
do{num=num/10;count++;}while(num>1);
System.out.println("它是个" + count + "位的数!");
}
}
2019-02-15
我是这样得到的
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
if (num/1000000000 < 10){
for(num = 999; num/10>=1;count++){
num = num-9*(num/10);}
System.out.print("它是个"+count+"位的数!");
}
else{
System.out.print("大于十位");
}
}
}
或者 if(num > -1000000000 && num < 1000000000) 也ok
举报