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

Prime Numbers 1 – N

Java – List All Prime Numbers Between 1 to N

Write a Java program to find all prime number between 1 to N. Where N is a number entered by the user at runtime.

Before writing this program you must know What is a prime number? and how to check if a number is prime or not.

Compile and run the program

javac PrimeNumber1ToN.java
java PrimeNumber1ToN

Output:

Enter max number:
100
List of the prime number between 1 - 100
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97