We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 0944bd5 + 698fc19 commit df35ab6Copy full SHA for df35ab6
1 file changed
PrimeNumber.java
@@ -0,0 +1,29 @@
1
+import java.util.Scanner;
2
+
3
4
5
+public class PrimeExample3 {
6
7
+ public static void main(String[] args) {
8
+ Scanner s = new Scanner(System.in);
9
+ System.out.print("Enter a number : ");
10
+ int n = s.nextInt();
11
+ if (isPrime(n)) {
12
+ System.out.println(n + " is a prime number");
13
+ } else {
14
+ System.out.println(n + " is not a prime number");
15
+ }
16
17
18
+ public static boolean isPrime(int n) {
19
+ if (n <= 1) {
20
+ return false;
21
22
+ for (int i = 2; i < Math.sqrt(n); i++) {
23
+ if (n % i == 0) {
24
25
26
27
+ return true;
28
29
+}
0 commit comments