-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprime1.java
More file actions
34 lines (32 loc) · 814 Bytes
/
prime1.java
File metadata and controls
34 lines (32 loc) · 814 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
import java.util.Scanner;
public class prime1{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.println("enter a number 'a': ");
int a = scn.nextInt();
System.out.println("enter another number 'b': ");
int b = scn.nextInt();
scn.close();
allprime(a,b);
}
public static void allprime(int a,int b)
{
int flag;
for(int i=a;i<b;i++)
{
flag=1;
for(int k=2;k<=(int)i/2;k++)
{
if(i%k==0)
{
flag=0;
break;
}
}
if(flag==1)
{
System.out.println(i);
}
}
}
}