-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimeNumber.java
40 lines (28 loc) Β· 908 Bytes
/
primeNumber.java
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
32
33
34
35
36
37
38
39
40
import java.util.Scanner;
public class primeNumber {
public static void main(String[] args) {
// check prime number
Scanner sc = new Scanner(System.in);
System.out.println("Enter the user value which you want to check");
int userInput = sc.nextInt();
if(userInput<=1){
System.out.println("UserInput is not prime :"+ userInput);
}else{
boolean isPrime =true;
for(int i = 2 ; i<Math.sqrt(userInput); i++){
if(userInput%i==0){
isPrime = false ;
break;
}
}
if(isPrime)
{
System.out.println("Number is prime : " + userInput);
}
else{
System.out.println("Number is not prime : "+ userInput);
}
}
sc.close();
}
}