Saturday, 11 August 2012

JAVA Program accepts an integer and display whether it is a single digit, two digit, three digits or more three digits.



import java.util.Scanner;


public class Q{


public static void main(String[] args){

int d, f, c = 0;
Scanner a = new Scanner(System.in);
     
System.out.println("Enter any no.:");
int n = a.nextInt();

while (n > 0) {

d = n % 10;
n = n / 10;
c++;
}

System.out.println("the digit of no is:" + c);

}

}

No comments:

Post a Comment