KnowledgeBoat Logo

Computer Applications

Create a program to find out if the number entered by the user is a two, three or four digits number.

Sample input: 1023
Sample output: 1023 is a 4 digit number.

Java

Java Conditional Stmts

13 Likes

Answer

import java.util.Scanner;

public class KboatNumber
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number: ");
        int n = in.nextInt();
        
        if (n >= 10 && n <= 99)
            System.out.println("Two Digit Number");
        else if (n >= 100 && n <= 999)
            System.out.println("Three Digit Number");
        else if (n >= 1000 && n <= 9999)
            System.out.println("Four Digit Number");
        else
            System.out.println("Please enter a 2, 3 or 4 digit number");
    }
}

Output

BlueJ output of Create a program to find out if the number entered by the user is a two, three or four digits number. Sample input: 1023 Sample output: 1023 is a 4 digit number.

Answered By

6 Likes


Related Questions