1. Home
  2. Java
  3. Java Examples
  4. First N Prime Numbers

First N Prime Numbers

Java – List the Starting N Prime Numbers

Write a Java program to list first N prime numbers. Where N is a number input by the user.

Compile and run the program

javac NPrimeNumbers.java
java NPrimeNumbers

Output:

Enter total required prime numbers:
5
A List of the first 5 prime numbers
2
3
5
7
11