-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise06_10.java
More file actions
33 lines (28 loc) · 855 Bytes
/
Copy pathExercise06_10.java
File metadata and controls
33 lines (28 loc) · 855 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
/*
* 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.
*/
/**
*
* @author jorda
*/
public class Exercise06_10 {
public static void main(String[] args) {
int numberOfPrime = -1;
for (int i = 1; i < 10000; i++) {
if(isPrime(i)){
numberOfPrime++;
}
}
System.out.println("The number of prime numbers < 10000 " + numberOfPrime);
}
public static boolean isPrime(int number) {
for (int divisor = 2; divisor <= number / 2; divisor++) {
if (number % divisor == 0) { // If true, number is not prime
return false; // number is not a prime
}
}
return true; // number is prime
}
}