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