-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay20.java
More file actions
50 lines (34 loc) · 851 Bytes
/
Day20.java
File metadata and controls
50 lines (34 loc) · 851 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
/*
Day 20 coding Statement : Write a program to identify if the number is Prime number or not
Description
Get a number as input from the user and check whether that number is prime or not.
A prime number is a number with factors as 1 and that number itself.
Input
1
Output
1 is not a prime number
Input
5
Output
5 is a prime number
*/
import java.util.*;
public class Day20
{
public static boolean isPrime(int n){
for(int i=2;i<Math.sqrt(n);i++){
if(n%i==0)
return false;
}
return true;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number : ");
int n=sc.nextInt();
if(isPrime(n))
System.out.println("It is a prime number.");
else
System.out.println("It is not a prime.");
}
}