判断回文素数 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;
}

主要利用了之前写的代码
判断回文代码
判断素数代码
动态增加数组代码

你可能感兴趣的:(判断回文素数 java)