Skip to content

Commit c7ccd25

Browse files
committed
Solution to check the Prime Number
1 parent 456c0ed commit c7ccd25

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎src/Assignments/PrimeNumber.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package Assignments;
2+
3+
import java.util.Scanner;
4+
5+
public class PrimeNumber {
6+
public static void main(String[] args) {
7+
8+
Scanner input = new Scanner(System.in);
9+
System.out.println("Enter the Number:");
10+
int n = input.nextInt();
11+
System.out.println(isPrime(n));
12+
}
13+
14+
static boolean isPrime(int n){
15+
16+
if (n <= 1){
17+
return false;
18+
}
19+
20+
int c = 2;
21+
while (c * c <= n){
22+
if (n % c == 0){
23+
return false;
24+
}
25+
c++;
26+
}
27+
return c * c > n;
28+
}
29+
}

0 commit comments

Comments
 (0)