-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo2.java
More file actions
43 lines (31 loc) · 1.01 KB
/
Demo2.java
File metadata and controls
43 lines (31 loc) · 1.01 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
//Purpose: The program is designed to list first 50 prime numbers. //forgot extra slash
/*Author: Zhitao Yin*/
/*Email: zyin3@gsu.edu*/
/*Last update: August 28, 2016*/
public class Demo2 { //class needs renaming
public static void main(String[] args) {
final int NUMBER_OF_PRIMES = 50; //changed from byte to int
final int NUMBER_OF_PRIMES_PER_LINE = 10; //missing semi colon
int count = 0; //needs space
int number = 2;
System.out.println("The fist 50 prime numbers are \n"); //missing the quotes
while (count < NUMBER_OF_PRIMES){
boolean isPrime = true;
for (int divisor = 2; divisor <= number/2; divisor++){ //change 3 to 2
if(number % divisor == 0){
isPrime = false;
break;
}
}
if (isPrime){
count++;
if (count % NUMBER_OF_PRIMES_PER_LINE ==0){
System.out.println(++number);
}
else System.out.print(number++ + " "); //move number to ++number to number++
}
else
number++;
}
}
}