Check Whether a Number is Prime or Not in Java

In this program, you will learn to check whether a given integer number is prime or not. This is done using a for loop or while loop in Java.

A prime number is a number which is divisible by only two numbers: 1 and itself. So, if any number is divisible by any other number, it is not a prime number.

Check Prime Number using a while loop

When you run the program, the output will be:

13 is a prime number.

Check Prime Number using a for loop

When you run the program, the output will be:

13 is a prime number.

Post a Comment

Thank you for vising

أحدث أقدم