package homework3; public class prime { public String printPrimes (int n) { int curPrime; int numPrimes; boolean isPrime; int [] primes = new int [10000]; primes [0] = 2; numPrimes = 1; curPrime = 2; while (numPrimes < n) { curPrime++; isPrime = true; for (int i = 0; i <= numPrimes-1; i++) { if (curPrime%primes[i]==0) { isPrime = false; break; } } if (isPrime) { primes[numPrimes] = curPrime; numPrimes++; } } String res = ""; for (int i = 0; i <= numPrimes-1; i++) { res = res + primes[i] + " "; } return res; } }
(a)
(b)
array out of bounds
(c)
n = 1
(d)
NC: {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
EC: {(1,2), (2,3), (3,4), (4,5), (5,6), (6,7), (7,5), (6,8), (5,9), (8,9), (9,2), (9,10), (10,2), (2,11), (11,12), (12,13), (13,14), (14,12), (12,15)}
PPC: { (1,2,3,4,5,6,7), (1,2,3,4,5,6,8,9,10),
(1,2,3,4,5,9,10), (1,2,11,12,15),
(1,2,11,12,13,14), (2,3,4,5,6,8,9,2),
(3,4,5,6,8,9,2,3), (4,5,6,8,9,2,3,4),
(5,6,8,9,2,3,4,5), (6,8,9,2,3,4,5,6),
(8,9,2,3,4,5,6,8), (9,2,3,4,5,6,8,9),
(2,3,4,5,6,8,9,10,2), (3,4,5,6,8,9,10,2,3),
(4,5,6,8,9,10,2,3,4), (5,6,8,9,10,2,3,4,5),
(6,8,9,10,2,3,4,5,6), (8,9,10,2,3,4,5,6,8),
(9,10,2,3,4,5,6,8,9), (10,2,3,4,5,6,8,9,10),
(2,3,4,5,9,2), (3,4,5,9,2,3),
(4,5,9,2,3,4), (5,9,2,3,4,5),
(9,2,3,4,5,9), (2,3,4,5,9,10,2),
(3,4,5,9,10,2,3), (4,5,9,10,2,3,4),
(5,9,10,2,3,4,5), (9,10,2,3,4,5,9),
(10,2,3,4,5,9,10), (3,4,5,6,8,9,2,11,12,15),
(3,4,5,6,8,9,2,11,12,13,14), (3,4,5,6,8,9,10,2,11,12,15),
(3,4,5,6,8,9,10,2,11,12,13,14), (3,4,5,9,2,11,12,15),
(3,4,5,9,2,11,12,13,14), (3,4,5,9,10,2,11,12,13,14),
(3,4,5,9,10,2,11,12,15), (5,6,7,5),
(6,7,5,6), (7,5,6,7),
(6,7,5,9,2,11,12,13,14), (6,7,5,9,2,11,12,15),
(6,7,5,9,10,2,11,12,13,14), (6,7,5,9,10,2,11,12,15),
(6,7,5,9,2,3,4), (6,7,5,9,10,2,3,4),
(7,5,6,8,9,2,3,4), (7,5,6,8,9,10,2,3,4),
(12,13,14,12), (13,14,12,13),
(14,12,13,14), (13,14,12,15)
}