嵌套語(yǔ)句應(yīng)該怎么寫(xiě)
Scanner?sc=new?Scanner(System.in); System.out.println("請(qǐng)輸入一個(gè)10位以內(nèi)的數(shù)字"); long?num=sc.nextInt(); int?count=0; while?(num>0){ ????count++; ????num=num/10; } System.out.println(count+"位數(shù)");
Scanner?sc=new?Scanner(System.in); System.out.println("請(qǐng)輸入一個(gè)10位以內(nèi)的數(shù)字"); long?num=sc.nextInt(); int?count=0; while?(num>0){ ????count++; ????num=num/10; } System.out.println(count+"位數(shù)");
舉報(bào)
2022-04-24
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("它是個(gè)"+count+"位的數(shù)!");
? ??
? ? }
}
2022-04-24
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("它是個(gè)"+count+"位的數(shù)!");
? ??
? ? }
}
2022-04-24
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("它是個(gè)"+count+"位的數(shù)!");
? ? }
}
2022-03-19
將一個(gè)語(yǔ)句放入另一個(gè)語(yǔ)句的循環(huán)操作中