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

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

完全理解不了,求解釋,代碼是抄答案的,是不是太笨了o(╥﹏╥)o

public class HelloWorld{

public static void main(String[] args){

int num = 9999;

int count = 0;

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

? ? while(num!=0){

? ? ? ? count++;

? ? ? ? num/=10;

? ? }

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

}else{

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

}

}

}


正在回答

8 回答

int num = 9999;

int count = 0;

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

? ? while(num!=0){

? ? ? ? count++;

? ? ? ? num/=10;

? ? }

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

}else{

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

}

while第一次判斷條件成立,執(zhí)行:count 變成1了 ?num變成999.9了 ? ?

while第二次判斷條件成立,執(zhí)行:count變成 2了 ?num變成99.9了

while第三次判斷條件成立,執(zhí)行:count變成3了 num變成 9.9了

while第四次判斷條件成立,執(zhí)行:count變成4了 num變成 0.9,因?yàn)槭莍nt變量類型(整數(shù)),所以num變成了0

while第五次判斷條件不成立,結(jié)束while循環(huán),進(jìn)入System

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

while第一次判斷條件成立,執(zhí)行:count?變成1了??num變成10了????
while第二次判斷條件成立,執(zhí)行:count變成?2了??num變成1了
while第三次判斷條件成立,執(zhí)行:count變成3了?num變成?0.1,因?yàn)槭莍nt變量類型,所以num變成了0
while第四次判斷條件不成立,結(jié)束while循環(huán),進(jìn)入System

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

weixin_慕函數(shù)9095607

如果int num=9999; while第一次判斷條件成立,執(zhí)行:count 變成1了 num變成999.9了 while第二次判斷條件成立,執(zhí)行:count變成 2了 num變成99.9了 while第三次判斷條件成立,執(zhí)行:count變成3了 num變成 9.9了 while第四次判斷條件成立,執(zhí)行:count變成4了 num變成 0.9,因?yàn)槭莍nt變量類型(整數(shù)),所以num變成了0 while第五次判斷條件不成立,結(jié)束while循環(huán),進(jìn)入System
2021-03-30 回復(fù) 有任何疑惑可以回復(fù)我~

說(shuō)錯(cuò)了,跟int沒(méi)有關(guān)系,在Java中,/出來(lái)的都是整數(shù),且并不會(huì)四舍五入。

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

因?yàn)槭?10,最后剩一個(gè)數(shù)的時(shí)候除出來(lái)是小數(shù),因?yàn)閚um是int型的,會(huì)默認(rèn)為0,計(jì)數(shù)器額外+1

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

public class HelloWorld{
??? public static void main(String[] args){
??????? int num = 999;
??????? int count = 0;

??????? if(num > 0 && num < 0x7FFFFFFF) {
??????????? while(num / 10 != 0) {
??????????????? count++;
??????????????? num /= 10;
??????????? }
??????????? System.out.println("他是個(gè)" + (count + 1) + "位的數(shù)!");
??????? } else {
??????????? System.out.println("輸入有誤");
??????? }
??? }
}

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

慕姐1003813

count為什么是以自加的方式進(jìn)行判斷num的位數(shù)呢,如果num循環(huán)到11,那count是1,循環(huán)到12,count不就是2了么
2020-11-04 回復(fù) 有任何疑惑可以回復(fù)我~
#2

qq_慕數(shù)據(jù)1267178 回復(fù) 慕姐1003813

12/10得出num是1,1/10的0.1,但num是int型,小數(shù)部分會(huì)丟棄,循環(huán)條件不成立,結(jié)束循環(huán)
2020-11-05 回復(fù) 有任何疑惑可以回復(fù)我~

public class HelloWorld{

public static void main(String[] args){

long num = 1111111111;

int count = 1;

while( num / 10 != 0 ){

? ? ? ? count +=1;

? ? ? ? num /= 10;?

? ? }

if(count>=10){

? ?System.out.println("重新輸");?

}else

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

?}

}


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

public class HelloWorld{

? ? public static void main(String[] args){

? ? ? ? int num = 999;

? ? ? ? int count = 0;

? ? ? ? while(num > 0){

? ? ? ? ? ? num /= 10;

? ? ? ? ? ? count++;

? ? ? ? ? ? if(num == 0)

? ? ? ? ? ? {

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

? ? ? ? ? ? }

? ? ? ? }

? ? }

}


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

慕沐2344328

為什么不可以是 while(num<1) 求解啊
2020-11-08 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慕桂英5256766 回復(fù) 慕沐2344328

額 因?yàn)閚um=999
2020-12-06 回復(fù) 有任何疑惑可以回復(fù)我~
#3

慕容3257468

老師,int不是只能取整數(shù)嗎,這里為什么不是 float num=999
2021-01-23 回復(fù) 有任何疑惑可以回復(fù)我~

就是給一個(gè)數(shù)值,讓它極大,然后呢,取出循環(huán)中通用的數(shù)值.

?int值除以一個(gè)數(shù)值,會(huì)產(chǎn)生一個(gè) 大于整數(shù)的值。

????比如:2位數(shù)是在 10-99 就是說(shuō)999 / 99, 還是0;

就是/999,若為0,它就是這個(gè)count位數(shù),

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

慕勒9944832 提問(wèn)者

count++; num/=10; 這個(gè)怎么理解。。o(╥﹏╥)o
2020-10-28 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慕工程4430411 回復(fù) 慕勒9944832 提問(wèn)者

就是說(shuō)呢,999/10 最多得到 99,就是少了一位數(shù),直到為0,就是位數(shù)的個(gè)數(shù)
2020-10-28 回復(fù) 有任何疑惑可以回復(fù)我~
#3

慕工程4430411 回復(fù) 慕勒9944832 提問(wèn)者

可以看看我下面寫(xiě)的代碼,好理解點(diǎn), 要理解,int值除以一個(gè)數(shù)值,會(huì)產(chǎn)生一個(gè) 大于整數(shù)的值。/ 10 就是將位數(shù)去掉最高的那一位
2020-10-28 回復(fù) 有任何疑惑可以回復(fù)我~
#4

慕勒9944832 提問(wèn)者 回復(fù) 慕工程4430411

大佬,這個(gè)是什么意思count++;
2020-10-28 回復(fù) 有任何疑惑可以回復(fù)我~
#5

慕勒9944832 提問(wèn)者 回復(fù) 慕工程4430411

我在回頭看看循環(huán)先吧,現(xiàn)在很懵
2020-10-28 回復(fù) 有任何疑惑可以回復(fù)我~
查看2條回復(fù)

舉報(bào)

0/150
提交
取消

完全理解不了,求解釋,代碼是抄答案的,是不是太笨了o(╥﹏╥)o

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

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

幫助反饋 APP下載

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

公眾號(hào)

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