The preceding Java code helps to get all the prime numbers present between the min and max values of the given series of numbers.
- import java.util.*;
- import java.lang.*;
- import java.io.*;
-
- class GetPrime
- {
- public static void main(String[] args) throws IOException
- {
-
- int max, min;
- System.out.println("Enter min and max values of series:");
-
- BufferedReader br = new BufferedReader(new InputStreamReader(System. in ));
-
- System.out.print("Min value is: ");
- min = Integer.parseInt(br.readLine());
-
- System.out.print("Max value is: ");
- max = Integer.parseInt(br.readLine());
-
- int i, n;
- System.out.println("Prime numbers from " + min + " to " + max + " is/are:");
-
- while (min != max)
- {
- for (i = 2; i < max; i++)
- {
- n = min % i;
- if (n == 0)
- {
- break;
- }
- }
- if (i == min)
- {
- System.out.println(min + " is Prime number!");
- }
- min++;
- }
- }
- }
Thank you, keep learning and sharing.