怎么出來的結(jié)果總是“它是個9位的數(shù)“呢
public class HelloWorld{
public static void main(String[] args){
int num = 999;
int count = 0;
int i;
if(num>0&&num<=999999999){
? ? for(i=0;i<9;i++){
? ? ? ? if(num/(10^i)>=1){
? ? ? ? ? ? count+=1;
? ? ? ? }
? ? }
System.out.println("它是個"+count+"位的數(shù)");
}
else
{
? ? System.out.println("請重新輸入數(shù)字!");
}
}
}
2016-06-30
好的,謝謝啦
2016-06-30
^直接用就是邏輯運算符異或,
2016-06-30
if (num >= 0 ?&& num<100000000){
while(num != 0){
count++;
num/=10;
}
System.out.println("它是個"+ count+"位的數(shù)!");
} else{
System.out.println("error!");
}
2016-06-30
java語言中不能直接用乘冪運算符,,,需要使用必須用函數(shù)Math.pow(x,3);