01
09
23
13
为了账号安全,请及时绑定邮箱和手机立即绑定

为什么这个不行呢

public class HelloWorld{

 public static void main(String[] args){ 

int num = 999; 

int count = 0;

if(num>0&&num<=999999999)

while(num>0){

count++;

  num/=10;   

}  

System.out.println("它是个"+count+"位的数!");   

}else{ 

   System.out.println("输入有误!");  

 } 

 } 

 } 

正在回答

代码语言

1 回答

代码一下,建议写代码要整齐,方便查看。你写的num="">0;count++){    num/=10;   乱了。  

public class HelloWorld{ 

public static void main(String[] args){ 

    int num = 999; 

    int count = 0; 

            if(num>0&&num<=999999999){ 

                if(num>0){ //判断位数

                   count++;

                   num/=10;   //每次除以10减少一位

                  }    

                System.out.println("它是个"+count+"位的数!");  

                 }else{   

                System.out.println("输入有误!");   

                }

     } 

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

举报

0/150
提交
取消

为什么这个不行呢

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号