// Arup Guha
// 7/19/05
// Solution to prime.java

import java.io.*;

public class prime {

  public static void main(String[] args) throws IOException {

    BufferedReader stdin = new BufferedReader
				(new InputStreamReader(System.in));

    // Get user input.
    System.out.println("Enter the lower bound of your range.");
    int low = Integer.parseInt(stdin.readLine());

    System.out.println("Enter the upper bound of your range.");
    int high = Integer.parseInt(stdin.readLine());

    // Keeps track of if the first value has been printed.
    boolean firstval = true; 

    // Print header.
    System.out.print("The prime numbers in between "+low+" and "+high+" are ");
 
    // Loop through all the values in the range.
    for (int tryval=low; tryval<=high; tryval++) {

      boolean prime = true;

      // Try dividing the number we are trying by all possibilities.
      // The +1 is to account for a possible rounding error.
      for (int trydiv=2; trydiv<=Math.sqrt(tryval)+1; trydiv++) {

        // If it divides evenly, the number isn't prime.
        if (tryval%trydiv == 0) {
          prime = false;
          break;
        }
      }

      // We only print something if the number is prime.
      if (prime) {

        // If it's the first number, don't precede it with a comma.
        if (firstval) {
          System.out.print(tryval);
          firstval = false;
        }

        // Otherwise, print a comma and then the value.
        else
          System.out.print(", "+tryval);
      }

    } //  end for tryval
    
    // Finish the sentence!
    System.out.println(".");

  } // end main

} // end class
