## Learn how to display program of the prime number between two number in java:

In this article, you’ll learn how to print all **prime number** between two given number in java language without giving input from the keyboard or giving input from the keyboard.

Q: what is the prime number

Ans: A natural number which only divided by itself and 1 is called a prime number and you also say that a prime number is a natural number which is greater than 1 and cannot be formed by multiplying two natural number.

- 1 is not a prime number.
- 2 is the smallest prime number and only even prime number.
- Example of prime number 2,3,5,7,11,13 etc.

To print all prime number between two given number we generally use the following steps:

- First, we take two number then add 1 in the first number and subtract 1 in the second number to check prime number between two intervals number.
- We use two for loop first,
**for loop**for checking all number between the intervals and second**for loop**to check prime number. - If second for loop is true, then it means the number is not a prime number and increments the number check again
- If second
**for loop**is false, then it checks again - if(i==x) then it a prime number and check again for the first for loop.

Example 1: write a program in java language to print all prime number between two given number, without input from the keyboard

public class primeNum {
System.
{
System. }}} |

Prime number are : 3 5 7 11 13 17 19 23 29 31 37 |

Example 2: write a program in java language to print all prime number including two given number, without input from keyboard Solution:

Solution:

public class primeNum {
System.
{
System. }}} |

Prime number are : 2 3 5 7 11 13 17 19 23 29 31 37 |

Note: in this program, the prime number printed including 2 and check up to 40.

Example 3: write a program in java language to print all prime number between two given number, with input from the keyboard

Solution:

import java.util.Scanner;
System. Scanner sc=
sc.close();
{
System. }}} |

The Output of this program:
Enter two number: 10 100 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 |

Example 4: write a program in C++ language to print all prime number including two given number, with input from keyboard Solution:

Solution:

import java.util.Scanner;
System. Scanner sc=
sc.close();
{
System. }}} |

The output of this program:
Enter two number: 11 100 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 |

You may also learn the following programming:

- Program of Armstrong Number in java
- Program of Fibonacci series in java
- Program to reverse a number in the java language