Java Program to list Prime numbers using for loop.

This post on Java Program to list Prime numbers using for loop is the same as the Java Program to check whether a number is prime or not.

The explanation is the same as checking for prime number, the only difference is that we set a last range number that is we take user input for the last number and check for prime number from 1 to that last number.

And if the boolean variable isPrime is true after checking for each number, it will print the number for each iteration.

Output:

Java Program to check whether a number is prime or not

Also, learn
Java Interview Programs