• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 07, 2022 |20.2K Views

Java Program to Check Prime Number

  Share  3 Likes
Description
Discussion

In this video, we will see how to check input number is prime or not 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 some prime numbers from 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 a prime numbers:
Step 1: First, take the numbers.
Step 2: Then use a for loop.
Step 3: Then check for a number to be a prime number. If it is a prime number, print it.

Check if a number is prime or not: https://www.geeksforgeeks.org/java-program-to-check-if-a-number-is-prime-or-not/