• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
May 31, 2022 |41.1K Views
Java Program to Print Prime Numbers from 1 to 100
  Share  5 Likes
Description
Discussion

In this video, we will see how to print prime numbers from 1 to 100 in the Java programming language. We know that “A prime number is a number that can only be divided by itself and 1 without remainders”. There are 25 prime numbers between 1 to 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]

Some interesting facts about prime numbers:
1. Two is the only even Prime number.
2. Every prime number can be represented in form of 6n+1 or 6n-1 except the prime number 2 and 3, where n is a natural number.
3. Two and Three are only two consecutive natural numbers that are prime.

Algorithm to print prime numbers:

Step 1: First, take the numbers from 1 to 100 as input.
Step 2: Then use a for loop to iterate the numbers from 1 to 100
Step 3: Then check for each number to be a prime number. If it is a prime number, print it.

Java Program to Print Prime Numbers from 1 to 100 :
https://www.geeksforgeeks.org/java-program-to-display-all-prime-numbers-from-1-to-n/