Example:
Input n : 3 Output : {2,3,5}
1. Initialize an ArrayList
object to store first n
prime numbers.
2. Loop for n
iterations.
3. Within the loop, find successive prime numbers by checking for the divisors between 2 and number/2
. Add these prime numbers to the arrayList
to be returned.
4. At the end of the loop, return the arrayList
containing n
prime numbers.
public static ArrayList<Integer> primeNumbers(int n) { }
C
Java
Python