forked from txs72/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumber.java
More file actions
executable file
·47 lines (45 loc) · 1.28 KB
/
PrimeNumber.java
File metadata and controls
executable file
·47 lines (45 loc) · 1.28 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
/* */ package ch05;
/* */
/* */ public class PrimeNumber {
/* */ public static void main(String[] args) {
/* 5 */ int NUMBER_OF_PRIMES = 50;
/* 6 */ int NUMBER_OF_PRIMES_PER_LINE = 10;
/* 7 */ int count = 0;
/* 8 */ int number = 2;
/* */
/* 10 */ System.out.println("The first 50 prime numbers are \n");
/* */
/* */
/* 13 */ while (count < 50) {
/* */
/* 15 */ boolean isPrime = true;
/* */
/* */
/* 18 */ for (int divisor = 2; divisor <= number / 2; divisor++) {
/* 19 */ if (number % divisor == 0) {
/* 20 */ isPrime = false;
/* */
/* */ break;
/* */ }
/* */ }
/* */
/* 26 */ if (isPrime) {
/* 27 */ count++;
/* */
/* 29 */ if (count % 10 == 0) {
/* */
/* 31 */ System.out.println(number);
/* */ } else {
/* */
/* 34 */ System.out.print(number + " ");
/* */ }
/* */ }
/* */
/* 38 */ number++;
/* */ }
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch05/PrimeNumber.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/