View Code of Problem 92

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);	
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		List list = new ArrayList();
		for(int i=a; i<=b; i++) {
			if(isHui(i) && isSu(i)) {
				list.add(i);
			}
		}
		int count = 0;
		for(int i=0; i<list.size(); i++) {
			System.out.printf("%6d",list.get(i));
			count++;
			if(count % 5 ==0) {
				System.out.println();
			}
			
		}
	}

	public static boolean isSu(int x) {
		// TODO Auto-generated method stub
		for(int i=2; i<=Math.sqrt(x); i++) {
			if(x%i == 0) {
				return false;
			}
		}
		return true;
	}

	public static boolean isHui(int x) {
		// TODO Auto-generated method stub
		String s = String.valueOf(x);
		int k =s.length()-1;
		int i = 0;
		while(i<k) {
			if(s.charAt(i++) != s.charAt(k--)) {
				return false;
			}
		}
		return true;
	}		
}

Double click to view unformatted code.


Back to problem 92