-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime.java
More file actions
29 lines (26 loc) · 807 Bytes
/
Prime.java
File metadata and controls
29 lines (26 loc) · 807 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
import java.util.Scanner;
public class Prime {
public static void main(String[] args) {
try (Scanner input = new Scanner(System.in)) {
System.out.println("Welcome to the Prime Number Checker!");
System.out.print("Enter a number: ");
int num = input.nextInt();
boolean isprime = isprime(num);
if (isprime) {
System.out.println("Your numberis Prime");
} else {
System.out.println("Your number is not Prime");
}
}
}
public static boolean isprime(int num) {
int i = 2;
while (i < num) {
if (num % i == 0) {
return false;
}
i++;
}
return true;
}
}