Lecture Notes on 18 Feb 2013 import java.util.*; public class Test { public static void main (String[] args) { Scanner sc = new Scanner (System.in); /* // Prompt the user to enter a number System.out.print ("Enter a number: "); // Read the number int num = sc.nextInt(); int num_orig = num; // Reverse the number int revNum = 0; while (num > 0) { revNum = revNum * 10 + (num % 10); num = num / 10; } System.out.println ("Reverse of the number = " + revNum); if (revNum == num_orig) { System.out.println (num_orig + " is palindromic"); } else { System.out.println (num_orig + " is not palindromic"); } num = num_orig; int limit = (int) Math.sqrt (num); boolean isPrime = true; for (int i = 2; i <= limit; i++) { if (num % i == 0) { isPrime = false; break; } } if (isPrime) { System.out.println (num + " is prime"); } else { System.out.println (num + " is not prime"); } */ // Print all palindromic primes in a given range System.out.print ("Enter low end: "); int lo = sc.nextInt(); System.out.print ("Enter high end: "); int hi = sc.nextInt(); for (int n = lo; n <= hi; n++) { int limit = (int) Math.sqrt (n); boolean isPrime = true; for (int i = 2; i <= limit; i++) { if (n % i == 0) { isPrime = false; break; } } int n1 = n; int n2 = n; if (isPrime) { int revN = 0; while (n1 > 0) { revN = revN * 10 + (n1 % 10); n1 = n1 / 10; } if (revN == n2) { System.out.print (n + " "); } } } System.out.println (); } }