To Count Number of Digit :
For Example : 12345
No of Digit : 5
//Source Code
import java.util.Scanner;
public class CountNumberOfDigit
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int num ,count=0;
System.out.print("Enter a Number To Check : ");
num = in.nextInt();
while(num!=0)
{
num=num/10;
count++;
}
System.out.print("No of Digit Of a Given No : "+count) ;
}
}
// Sample Input :
Enter a Number To Check : 123
// Sample Output:
No of Digit Of a Given No : 3
// Sample Input :
Enter a Number To Check : 16385
// Sample Output:
No of Digit Of a Given No : 5
For Example : 12345
No of Digit : 5
//Source Code
import java.util.Scanner;
public class CountNumberOfDigit
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int num ,count=0;
System.out.print("Enter a Number To Check : ");
num = in.nextInt();
while(num!=0)
{
num=num/10;
count++;
}
System.out.print("No of Digit Of a Given No : "+count) ;
}
}
// Sample Input :
Enter a Number To Check : 123
// Sample Output:
No of Digit Of a Given No : 3
// Sample Input :
Enter a Number To Check : 16385
// Sample Output:
No of Digit Of a Given No : 5
0 Comments