Write a Java Program to Display Prime Numbers Between Intervals Using Function

Java Program to Display Prime Numbers Between Intervals Using Function

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 Intervals Using Function
Java Program to Display Prime Numbers Between Intervals Using Function

Write a Java Program to Display Prime Numbers Between Intervals Using Function

PROGRAM: Java Program to Display Prime Numbers Between Intervals Using Function

/* Java Program to Display Prime Numbers Between Intervals Using Function */

public class Prime {

public static void main(String[] args) {

int low = 20, high = 50;

while (low < high) {
if(checkPrimeNumber(low))
System.out.print(low + ” “);

++low;
}
}

public static boolean checkPrimeNumber(int num) {
boolean flag = true;

for(int i = 2; i <= num/2; ++i) {

if(num % i == 0) {
flag = false;
break;
}
}

return flag;
}
}

Leave a Reply

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