Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Q 12 Print prime numbers between two numbers
- import java.util.*;
- public class Main
- {
- static boolean check(int n){
- int i=2;
- while(i*i <= n){
- if(n%i==0){
- return false;
- }
- i++;
- }
- return true;
- }
- public static void main(String[] args) {
- Scanner sc= new Scanner(System.in);
- System.out.println("Enter the first number");
- int a = sc.nextInt();
- System.out.println("Enter the second number");
- int b = sc.nextInt();
- while(a<b){
- a++;
- if(check(a)){
- System.out.print(a+" ");
- }
- }
- }
- }
- /*
- Enter the first number
- 5
- Enter the second number
- 20
- 7 11 13 17 19
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement