输入一个整数,判断它是几位数

    //输入一个整数,判断它是几位数
    public static void test05(int num){
        int count = 0;
        do {
            num = num/10;
            count++;
        }while(num!=0);
        System.out.println("这是"+count+"位数");
    }
    
    
    
    //输入一个整数,判断它是几位数,并输出各位之和
    public static void test06(int num){
        int count = 0;
        int sum = 0;
        do {
            sum = sum+num%10;
            num = num/10;
            count++;
        }while(num!=0);
        System.out.println("这是"+count+"位数");
        System.out.println("各位之和是:"+sum);
    }

你可能感兴趣的:(Java小题)