L11: Loop-III (Nested Loop)

Q1. Write a program that reads two numbers and prints all the prime numbers present within the input numbers.

import java.util.Scanner;
class Test {
  public static void main(String[ ] args) {
    Scanner ip=new Scanner(System.in);
    System.out.print("Enter two numbers: ");
    int a=ip.nextInt();
    int b=ip.nextInt();
    System.out.println("The prime numbers are: ");
    for(int i=a+1;i < b;i++) {
      boolean isPrime=true;
      int factor=2;
      while(factor<=Math.sqrt(i)) {
        if(i % factor==0){
        isPrime=false;
        break;
        }
      factor++;
      }
    if(isPrime)
      System.out.print (i + "\t");
      }
   }
}