第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

循環(huán)可以用別的嗎?

if(num>=0&&num<=999999999){

? ? while(num!=0){

? ? ? ?count++;

? ? ? ?num/=10;

? ? }

? ? System.out.println("它是個(gè)"+count+"位的數(shù)");

}else{

? ? System.out.println("輸入有誤!");

}

改為for循環(huán)

正在回答

3 回答

public class HelloWorld{

public static void main(String[] args){

int num = 118579;

int count = 0;

?for(count=0;count<10;count++)

?{

? ? ?if(num%10!=0||num>0)

? ? ?{

? ? ? ? ?num=num/10;

? ? ?}

? ? ?else

? ? ?{

? ? ? ? ?System.out.println("它是個(gè)"+count+"位的數(shù)!");

? ? ? ? ?break;

? ? ?}

?}

}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

public class HelloWorld{

public static void main(String[] args){

int num = 999;

int count = 0;

for(;num>0; num=num/10){

? ? if(num%10!=0){

? ? count++;

? ? }

}

System.out.println("它是個(gè)"+count+"位的數(shù)!");

}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

weixin_慕數(shù)據(jù)7596515

你這樣換個(gè)數(shù)就是錯(cuò)誤的內(nèi)容。
2019-06-08 回復(fù) 有任何疑惑可以回復(fù)我~
#2

weixin_慕數(shù)據(jù)7596515

你把num的值換成可以被整除的數(shù),都會(huì)變成1位數(shù),應(yīng)該吧count++放到if語(yǔ)句之外,for語(yǔ)句之內(nèi)。
2019-06-08 回復(fù) 有任何疑惑可以回復(fù)我~
#3

慕瓜5579907 回復(fù) weixin_慕數(shù)據(jù)7596515

看到了 for循環(huán)里只放count++就行了 不需要if語(yǔ)句
2019-06-12 回復(fù) 有任何疑惑可以回復(fù)我~
#4

慕瓜5579907 回復(fù) weixin_慕數(shù)據(jù)7596515

數(shù)字是0的時(shí)候會(huì)輸出是個(gè)0位的數(shù) 所以還需要一個(gè)if判斷是否為0 public static void main(String[] args) { int num = 0; int count = 0; if(num == 0){ System.out.println("它是個(gè)1位的數(shù)!"); }else{ for(;num>0; num=num/10){ count++; } System.out.println("它是個(gè)"+count+"位的數(shù)!"); } }
2019-06-12 回復(fù) 有任何疑惑可以回復(fù)我~
#5

慕瓜5579907 回復(fù) 慕瓜5579907

public static void main(String[] args) { int num = -1; int count = 0; if(num<0){ System.out.println("輸入有誤"); }else if(num == 0){ System.out.println("它是個(gè)1位的數(shù)"); }else{ for(;num>0; num=num/10){ count++; }System.out.println("它是個(gè)"+count+"位的數(shù)"); } }
2019-06-12 回復(fù) 有任何疑惑可以回復(fù)我~
查看2條回復(fù)

public class HelloWorld{

public static void main(String[] args){

int num = 999;

int count = 0;


do

{

? ? count++;

? ? num=num/10;?

}

while(num >0);


System.out.println("它是個(gè)" + count + "位的數(shù)!");

}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

循環(huán)可以用別的嗎?

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)