KnowledgeBoat Logo

Computer Applications

Write a program to input a number in the range 10 to 100 and check if it is a prime number.

Java

Java Iterative Stmts

11 Likes

Answer

import java.util.Scanner;

public class KboatPrime
{
    public static void main(String args[]) {
        System.out.print("Enter a number between 10 to 100 : ");
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        
        int c = 0;
        
        if(num < 10 || num > 100)
            System.out.println("Number out of range");
        else    {
            for (int i = 1; i <= num; i++) {
                if (num % i == 0)
                    c++;
            }
            if (c == 2)
                System.out.println("Prime number");
            else
                System.out.println("Not a prime number");
        }
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program to input a number in the range 10 to 100 and check if it is a prime number.BlueJ output of Write a program to input a number in the range 10 to 100 and check if it is a prime number.

Answered By

3 Likes


Related Questions