Java Program to Print All Prime Numbers in an Interval
In This Program We Learn to Print All Prime Numbers in an Interval
Example: Code Program
import java.util.*;
public class PrimeNum {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int l, h, j, f = -1;
System.out.print("Enter Starting Point:");
l = sc.nextInt();
System.out.print("Enter Ending Point:");
h = sc.nextInt();
System.out.print("Prime Number Between "+l+" and "+h+ " are\n" );
while(l<h) {
f = -1;
j = 2;
while(j < l/2) {
if(l%j == 0)
f = f+1;
j = j+1;
}
if(f == -1)
System.out.print(l+" ");
l = l+1;
}
}
}
Output:
Python Program Code
Post a Comment