Input a Number and Count its Digit

Input a Number and Count its Digit

Previous Home Next

 

Input a Number and Count its Digit

 

 //Following program for Insert a number And Count its Digit.
package r4r.co.in;

import java.io.*;

public class NewClass {

    public static void main(String[] args) throws IOException {

        BufferedReader Digit = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the Digit:");
        String s1 = Digit.readLine();
        int n1 = Integer.parseInt(s1);

        //Code
        int p = 0;
        while (n1 != 0) {
            n1 = n1 / 10;
            p++;
        }

        System.out.println("Total Digit is:" + p);
    }
}

Enter the Digit:
12343456
Total Digit is:8
Previous Home Next