write a program to check whether a number is 1 digit 2 digit number or three digit number in java
Answers
Answered by
17
Hey There!!
Here is a program which will work for any number of digits:
import java.util.Scanner;
public class DigitCount
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
int d=0;
while(n!=0)
{
n = n/10;
d++;
}
System.out.println("Number of digits is: "+d);
}
}
Hope it helps
Purva
Brainly Community
Here is a program which will work for any number of digits:
import java.util.Scanner;
public class DigitCount
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = sc.nextInt();
int d=0;
while(n!=0)
{
n = n/10;
d++;
}
System.out.println("Number of digits is: "+d);
}
}
Hope it helps
Purva
Brainly Community
QGP:
You are welcome :)
Similar questions