-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimeinrange.java
49 lines (45 loc) · 1.18 KB
/
primeinrange.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
41
42
43
44
45
46
47
48
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication4;
/**
*
* @author rakshitmalhotra
*/
import java.util.*;
import java.lang.*;
import java.lang.Math;
public class JavaApplication4 {
//Program to check prime number
public static void main(String args[])
{
int s1, s2, s3, flag = 0, i, j;
Scanner s = new Scanner(System.in);
System.out.println ("Enter the lower limit :");
s1 = s.nextInt();
System.out.println ("Enter the upper limit :");
s2 = s.nextInt();
System.out.println ("The prime numbers in between the entered limits are :");
for(i = s1; i <= s2; i++)
{
for( j = 2; j < i; j++)
{
if(i % j == 0)
{
flag = 0;
break;
}
else
{
flag = 1;
}
}
if(flag == 1)
{
System.out.println(i);
}
}
}
}