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