Writing Prime Numbers between two numbers

“Writing Prime Numbers between two numbers” is a simple Java program which prints out prime numbers between two give number.

import java.util.*;

public class PrimeNumber
public static void main(String args [])
Scanner sc = new Scanner(System.in);
int num1, num2;
System.out.println("Please enter the first number");
num1 = sc.nextInt();
System.out.println("Please enter the Second number");
num2 = sc.nextInt();
System.out.println("Prime number: ");
for (int i=num1; i <= num2; i++ ){
int j;
for (j=2; j<i; j++){
int n = i%j;
if (n==0){
if(i == j){
System.out.print(" "+i);

Leave a Reply

Your email address will not be published. Required fields are marked *