The first 100 prime numbers list

broken image
broken image

After running the prime number algorithm for each number we are pushing it into ArrayList if it is a prime number. Now we have two for loops first for loop is for looping over all the numbers between 1 to 100 and the second for loop is our previous prime number algorithm. In the above code, we’ve declared an ArrayList that stores all the prime numbers in the range of 1 to 100. Here’s the code to do that.Ĭheck out upGrad’s Java Bootcamp int n = 5

broken image

If the count is 2 then we can conclude that the given number is a prime, else it is not a prime. At first, we need to loop over all the numbers from 1 to N and maintain a count of numbers that properly divides the given number. Before jumping to the code, we’ll understand the algorithm to check if a number is a prime number or not.

broken image