亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

嵌套語句應該怎么寫

Scanner?sc=new?Scanner(System.in);
System.out.println("請輸入一個10位以內的數字");
long?num=sc.nextInt();
int?count=0;

while?(num>0){
????count++;
????num=num/10;
}
System.out.println(count+"位數");


正在回答

4 回答

public class HelloWorld{

public static void main(String[] args){

? ? int num = 999;

? ? int count = 0;

? ? for(int x=1;x<=num;x*=10){

? ? ? ? if(x<=num/10){

? ? ? ? ? ? ? ?continue;

? ? ? ? ? ?}

? ? ? ? for(int i=1;i<=x;i*=10){

? ? ? ? ? ?

? ? ? ? ? ? count++;


? ? ? ? }

? ? }

? ? if(num==0){

? ? ? ? count+=1;

? ? }

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

? ??

? ? }

}


0 回復 有任何疑惑可以回復我~

public class HelloWorld{

public static void main(String[] args){

? ? int num = 999;

? ? int count = 0;

? ? for(int x=1;x<=num;x*=10){

? ? ? ? for(int i=1;i<=x;i*=10){

? ? ? ? ? ? count++;

? ? ? ? ? ? break;

? ? ? ? }

? ? }

? ? if(num==0){

? ? ? ? count+=1;

? ? }

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

? ??

? ? }

}


0 回復 有任何疑惑可以回復我~

public class HelloWorld{

public static void main(String[] args){

? ? int num = 999;

? ? int count = 0;

? ? for(int x=1;x<=num;x*=10){

? ? ? ? for(int i=10;i<=x;i*=10){

? ? ? ? ? ? count++;

? ? ? ? }

? ? }

? ? if(num==0){

? ? ? ? count+=1;

? ? }

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

? ? }

}


0 回復 有任何疑惑可以回復我~

將一個語句放入另一個語句的循環操作中

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Java入門第一季(IDEA工具)升級版
  • 參與學習       1167758    人
  • 解答問題       18749    個

0基礎萌新入門第一課,從Java環境搭建、工具使用、基礎語法開始

進入課程

嵌套語句應該怎么寫

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號