-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ11_PrimeOrNot.java
More file actions
31 lines (23 loc) · 814 Bytes
/
Q11_PrimeOrNot.java
File metadata and controls
31 lines (23 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 11. Program to check given number is prime or not.
import java.util.Scanner;
public class Q11_PrimeOrNot {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
System.out.print("11. Program to check given number is prime or not.\n\n");
System.out.println("Enter the numbers to check no. is prime or not : ");
int num = myObj.nextInt();
boolean flag = false;
for (int i = 2; i <= num / 2; ++i){
if (num % i == 0) {
flag = true;
break;
}
}
if (!flag){
System.out.println(num + " is a prime number.");
}else{
System.out.println(num + " is not a prime number.");
}
System.out.printf("\nThank You");
}
}