為啥答案是0
public class Demo1{
public static void main(String[] args) {
int num = 999;
int count = 0;
for(int i=0;num==0;++count)
{
? ? num/=10;
? ??
}
System.out.println("它是個"+count+"位的數(shù)!");
? ? ? ? ? ??
? ? ? ? }
public class Demo1{
public static void main(String[] args) {
int num = 999;
int count = 0;
for(int i=0;num==0;++count)
{
? ? num/=10;
? ??
}
System.out.println("它是個"+count+"位的數(shù)!");
? ? ? ? ? ??
? ? ? ? }
2018-09-11
舉報
2018-09-12
2018-09-11
for循環(huán)的“==”改為“!=”。因為如果for循環(huán)的條件為判斷是否等于0的話,就不會進(jìn)循環(huán),所以count的值不變且為0.