-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYT58.java
More file actions
68 lines (51 loc) · 1.39 KB
/
YT58.java
File metadata and controls
68 lines (51 loc) · 1.39 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*Write a program to input a number and check whether it is a prime number or not.
*If it is not a prime number then display the next number that is prime.
*Sample Input:14
*Sample Output: 17
*/
import java.io.*;
class YT58
{
public static void main(String[] args)throws IOException
{
int n;
int c=0, r=0, v=0;
int c1=0;
InputStreamReader I = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(I);
System.out.println("Enter the number which you want to check: ");
n=Integer.parseInt(br.readLine());
for (int i=1; i<=n; i++)
{
if(n%i==0)
{
c++;
}
}
if (c==2)
{
System.out.println("Prime Number: "+n);
}
else
{
r=n+10;
for(int i=n+1; i<=r; i++)
{
v=i;
for(int j=1; j<=v; j++)
{
if(v%j==0)
{
c1++;
}
}
if(c1==2)
{
System.out.println("Next Prime: "+v);
break;
}
c1=0;
}
}
}
}