Computer Applications
Write a program that takes a number and check if the given number is a 3 digit number or not. (Use a loop to determine)
Java
Java Iterative Stmts
7 Likes
Answer
import java.util.Scanner;
public class KboatDigitCount
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = in.nextInt();
int count = 0;
while (n != 0) {
count++;
n = n / 10;
}
if (count == 3)
System.out.println("Three digit number");
else
System.out.println("Not a three digit number");
}
}
Variable Description Table
Program Explanation
Output


Answered By
1 Like
Related Questions
Write a program that takes a number and check if the given number is a 3 digit number or not. (Use if to determine)
Write a program to input three numbers and print the largest of the three numbers.
Write a program that prints the squares of 10 even numbers in the range 10 .. 100.
Palindrome Number in Java: Write a program to accept a number from the user and check whether it is a Palindrome number or not. A number is a Palindrome which when reads in reverse order is same as in the right order.
Sample Input: 242
Sample Output: A Palindrome numberSample Input: 467
Sample Output: Not a Palindrome number