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

Java Program 1 Input Output Pages

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)
2 views2 pages

Java Program 1 Input Output Pages

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
You are on page 1/ 2

Program 1: Prime Number Check - Code

import java.util.Scanner;

class PrimeNumberCheck {
public static void main(String args[]) {
int temp;
boolean isPrime = true;
Scanner scan = new Scanner(System.in);
System.out.println("Enter any Number:");
int num = scan.nextInt();
scan.close();

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


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

if (isPrime)
System.out.println(num + " is a Prime Number.");
else
System.out.println(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