Write a Java Program to Display Prime Numbers Between Two Intervals

Java Program to Display Prime Numbers Between Two Intervals

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Display Prime Numbers Between Two Intervals
Java Program to Display Prime Numbers Between Two Intervals

Write a Java Program to Display Prime Numbers Between Two Intervals

PROGRAM: Java Program to Display Prime Numbers Between Two Intervals

/* Java Program to Display Prime Numbers Between Two Intervals */

public class Prime {

public static void main(String[] args) {

int low = 20, high = 50;

while (low < high) {
boolean flag = false;

for(int i = 2; i <= low/2; ++i) {
// condition for nonprime number
if(low % i == 0) {
flag = true;
break;
}
}

if (!flag && low != 0 && low != 1)
System.out.print(low + ” “);

++low;
}
}
}

Leave a Reply

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