我的代碼咋錯了
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
if(count<10){count++;
? ? while(num/10^count<1){
? ? ? ? count-=1;
? ? ? ? break;
? ??
}
? ? System.out.println("它是個"+ count+"位的數(shù)!");
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
if(count<10){count++;
? ? while(num/10^count<1){
? ? ? ? count-=1;
? ? ? ? break;
? ??
}
? ? System.out.println("它是個"+ count+"位的數(shù)!");
2018-01-29
舉報
2018-01-29
如過我沒記錯的話“^”是個“異或”的判斷語句,這個值在你這個程序里面好像沒法執(zhí)行while語句
你可以看看我寫的這個,加入了輸入
package practice;
//任務:判斷一個數(shù)(小于10位)的位數(shù)。
import java.util.Scanner;
public class HelloWorld {
?public static void main(String args[]) {
?Scanner input = new Scanner(System.in);//創(chuàng)建Scanner對象
?System.out.println("請輸入一個數(shù)字:");
?int num= input.nextInt();//輸入并儲存
?int count=0;
?if(num<999999999) {
??while(num!=0) {
???count++;
???num/=10;
??}
??System.out.println("這是一個"+count+"位數(shù)。");
?}
?else {System.out.print("請輸入一個位數(shù)小于10的數(shù)。");}
?}
}