- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumber.java
More file actions
Latest commit
31 lines (29 loc) · 506 Bytes
/
Copy pathPrimeNumber.java
File metadata and controls
31 lines (29 loc) · 506 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
importjava.util.Scanner;
publiclassPrimeNumber
{
publicstaticvoidmain(String[] args)
{
inttemp;
booleanisPrime=true;
System.out.println("Enter Number:");
Scannersc = newScanner(System.in);
intnumber=sc.nextInt();
for(inti = 2; i<=number/2; i++)
{
temp = number%i;
if(temp==0)
{
isPrime=false;
break;
}
}
if(isPrime)
{
System.out.println(number +" is a prime number");
}
else
{
System.out.println(number +" is not a prime number");
}
}
}