1. 程式人生 > >判斷迴文素數 java

判斷迴文素數 java

程式碼

private static void funtion(int a) {
	// TODO Auto-generated method stub
	final int NUMBER_OP = 10;
	int mun = 2, total = 0;
	while (true) {
		if (mun == a)
			break;
		boolean prime = true;
		for (int resdiut = 2; resdiut <= mun / 2; resdiut++) {
			if (mun % resdiut == 0){
			    prime = false
; break; } } if (prime == true && hueiwen(mun)) { total++; if (total % NUMBER_OP == 0) System.out.println(mun); else System.out.print(mun + " "); } mun++; } } private static boolean hueiwen(int a) { int [] arr = new int [1]; int i = 0; while(true) { arr[
i] = a%10; i++; a /= 10; if(a == 0) break; arr= newArr(arr); } int temp = arr.length - 1; for (int j = 0; j < temp; j++) { if(arr[j]==arr[temp]) { temp--; } else { return false; } return true; } return false; } private static int[] newArr(int[] oldArr)
{ int newLength = oldArr.length + 1; int[] _newArr = new int[newLength]; for (int i = 0; i < oldArr.length; i++) { _newArr[i] = oldArr[i]; } return _newArr; }

主要利用了之前寫的程式碼
判斷迴文程式碼
判斷素數程式碼
動態增加陣列程式碼