求解釋,不知道哪里錯了
public class HelloWorld{ ? ?public static void main(String[] args){ ? ? ? ?int num = 999; ? ? ? ?for(int count = 1;count<10;count++){ ? ? ? ? ? ?num/=10; ? ? ? ? ? ?if(num<1){ ? ? ? ? ? ? ? ?System.out.println("它是個"+count+"位的數(shù)"); ? ? ? ? ? ? ? ?break; ? ? ? ? ? ?} ? ? ? ?} ? ?} } 哪里出錯了?
2018-03-09
我運算出來沒錯,按你的代碼
2018-03-07
我把你的代碼直接用,沒有發(fā)現(xiàn)問題啊
2018-03-07
public class HellowWorld{
public static void main(string[] args){
int num=999;
for(int count=1;count<10;count++){
num/=10;
if(num<1){
System.out.println("它是個"+"位的數(shù)");
}
}
}
}
2018-03-07
你的break事實上只是終止了if的循環(huán),而控制for的循環(huán)是count,count一定要自加到10才會終止。在count=3的之后都會滿足num<1,所以應(yīng)該會輸出“它是個3位的數(shù)、它是個4位的數(shù)......、它是個9位的數(shù)。