问答详情
源自:4-15 编程练习

请问怎么修改才能显示它是个3位的数!

public class HelloWorld{

public static void main(String[] args){

int num = 999;

int count = 0;

do{count++;

    num/=10

}

while(num>0);

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


提问者:江耀楠 2017-05-22 20:17

个回答

  • 慕斯3465619
    2017-05-22 20:54:21
    已采纳

    public class HelloWorld{

        public static void main(String[] args){

            int num = 999;    

            int count = 0;    

            for(; num > 0; count++){    

                num /= 10;

            }

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

        }

    }


  • 靖朝
    2017-05-22 20:28:15

    public class HelloWorld{

    public static void main(String[] args){

    int num = 999;

    int count = 0;

    while(num!=0){

        num/=10;

        count++;

    }



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






    }

    }