-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime.java
More file actions
49 lines (46 loc) · 749 Bytes
/
prime.java
File metadata and controls
49 lines (46 loc) · 749 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
import java.io.*;
class Prime
{
static boolean prime(int num)
{
if (num>2)
{
for (int i=2;i<num;i++)
{
if(num%i!=0)
continue;
else
return false;
}
return true;
}
else return true;
}
static void generate(int num1)
{
int count=0;
for(int i=2;;i++)
{
if (count<num1)
{
boolean x = prime(i); // can't use this.prime
if (x == true)
{
System.out.println(i);
count+=1;
}
}
else break;
}
}
}
class Methods
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("How many primes? ");
int num = Integer.parseInt(br.readLine());
Prime.generate(num);
}
}