package ProjectEuler;
public class Problem07 {
public static void main(String[] args) {
int[][] testNumbers = {
{1, 2},
{2, 3},
{3, 5},
{4, 7},
{5, 11},
{6, 13},
{20, 71},
{50, 229},
{100, 541}
};
for (int[] number : testNumbers) {
assert solution1(number[0]) == number[1];
}
}
private static boolean isPrime(int number) {
if (number == 2) {
return true;
}
if (number < 2 || number % 2 == 0) {
return false;
}
for (int i = 3, limit = (int) Math.sqrt(number); i <= limit; i += 2) {
if (number % i == 0) {
return false;
}
}
return true;
}
private static int solution1(int n) {
int count = 0;
int number = 1;
while (count != n) {
if (isPrime(++number)) {
count++;
}
}
return number;
}
}