Advertisement
tampurus

12 prime series between two numbers

Apr 2nd, 2022 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. // Q 12 Print prime numbers between two numbers
  2. import java.util.*;
  3. public class Main
  4. {
  5.     static boolean check(int n){
  6.         int i=2;
  7.         while(i*i <= n){
  8.             if(n%i==0){
  9.                 return false;
  10.             }
  11.             i++;
  12.         }
  13.         return true;
  14.     }
  15.     public static void main(String[] args) {
  16.         Scanner sc= new Scanner(System.in);
  17.         System.out.println("Enter the first number");
  18.         int a = sc.nextInt();
  19.         System.out.println("Enter the second number");
  20.         int b = sc.nextInt();
  21.         while(a<b){
  22.            a++;
  23.            if(check(a)){
  24.                 System.out.print(a+" ");
  25.            }
  26.         }
  27.     }
  28. }
  29.  
  30. /*
  31. Enter the first number
  32. 5
  33. Enter the second number
  34. 20
  35. 7 11 13 17 19
  36. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement