為啥答案是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+"位的數!");
? ? ? ? ? ??
? ? ? ? }
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+"位的數!");
? ? ? ? ? ??
? ? ? ? }
2018-09-11
舉報
2018-09-12
2018-09-11
for循環的“==”改為“!=”。因為如果for循環的條件為判斷是否等于0的話,就不會進循環,所以count的值不變且為0.