-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrimeNumber.java
More file actions
52 lines (44 loc) · 848 Bytes
/
Copy pathPrimeNumber.java
File metadata and controls
52 lines (44 loc) · 848 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package JavaPgm;
import java.util.Scanner;
public class PrimeNumber {
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Please enter a number to check prime/not prime");
int n=sc.nextInt();
System.out.println("you have intered "+n);
prime(n);
sc.close();
}
public static void prime(int x)
{
boolean flag=false;
if(x<=0)
{
System.out.println("Please enter +ve number");
}
else if(x==1)
{
System.out.println("given number is prime");
}
else
{
for(int i=2;i<x;i++)
{
if(x%i==0 && x!=i)
{
flag=true;
break;
}
}
if(flag)
{
System.out.println("given number is not prime");
}
else
{
System.out.println("given number is prime");
}
}
}
}