0% found this document useful (0 votes)
5 views2 pages

Java Prime Number Checker

The document contains a Java program that checks if a given number is prime. It prompts the user to enter a number, evaluates its primality by checking divisibility, and then outputs whether the number is prime or not. Example outputs for the numbers 7 and 10 are provided, demonstrating the program's functionality.

Uploaded by

tasnimfatmaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Prime Number Checker

The document contains a Java program that checks if a given number is prime. It prompts the user to enter a number, evaluates its primality by checking divisibility, and then outputs whether the number is prime or not. Example outputs for the numbers 7 and 10 are provided, demonstrating the program's functionality.

Uploaded by

tasnimfatmaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program 1: Prime Number Check - Code

import [Link];

class PrimeNumberCheck {
public static void main(String args[]) {
int temp;
boolean isPrime = true;
Scanner scan = new Scanner([Link]);
[Link]("Enter any Number:");
int num = [Link]();
[Link]();

for (int i = 2; i <= num / 2; i++) {


temp = num % i;
if (temp == 0) {
isPrime = false;
break;
}
}

if (isPrime)
[Link](num + " is a Prime Number.");
else
[Link](num + " is not a Prime Number.");
}
}
Program 1: Prime Number Check - Output
Enter any Number:
7
7 is a Prime Number.

Enter any Number:


10
10 is not a Prime Number.

You might also like