Public classPalindromeNumber2 {/* Generate a digit palindrome number * *private voidAdigit (LongParentnumber,LongTenid) {LongTenidresult = (Long) Math.pow (Tenid); for(inti = 0; I <= 9; i++) {System. out. println (Long) (Parentnumber + (i * tenidresult))); }/* Generate two digits */private voidTwodigit (LongParentnumber,LongTenid,BooleanIszero) {inti = 0;if(iszero) i = 0;Elsei = 1;LongTenidresult = (Long) Math.pow (Tenid); for(; I <= 9; i++) {System. out. println (Long) (Parentnumber + * I * tenidresult)); }/* Generate three digits */private voidThreedigit (LongParentnumber,LongTenlid,BooleanIsthree,LongTenid) {Longi = 1;if(!isthree) i = 0; for(; I <= 9;) {Longresult = Parentnumber;if(Isthree) {Adigit (Long) (I * MATH.POW (2) + i), Tenid); }Else{result + = I * MATH.POW (2 * tenid-tenlid) + i * MATH.POW (ten, tenlid);
SYSTEM.OUT.PRINTLN ("3 digits" +i+ "P ..." +result+ "i>>>>>" +i);
Adigit (result, Tenid);
} ++i; }/* Generate four-digit digit digits/private voidFourdigit (LongParentnumber,LongTenfid,LongTenlid,BooleanIsfour,LongTenid) {Longi = 1;if(!isfour) i = 0; for(; I <= 9; i++) {if(Isfour) {Twodigit (Long) (I * MATH.POW (3) + i), Tenid,true); }Else{Twodigit (Long) (I * MATH.POW (TENFID) + i * MATH.POW (ten, Tenlid) + parentnumber), tenID-1,true); }/* Specifies a palindrome digital print from single-digit digits to n digitsPublic voidPalindromenumber (LongN) {if(n <= 0) return;if(N > 4) {Palindromenumber (4); for(inti = 1; I <= N; i++) {if(i = = 1) {adigit (0, 0);Continue; }else if(i = = 2) {twodigit (0, 0,false);Continue; }else if(i = = 3) {threedigit (0, 0,true, 1);Continue; }else if(i = = 4) {fourdigit (0, 0, 0,true, 1);Continue; Odddigitpalindromenumber (i, 0,false, 0, 0); }
}
}Public voidPalindromenumber (LongN) { for(inti = 1; I < n;
i++) {palindromenumber (n); }
}Public voidOdddigitpalindromenumber (LongNLongTenid,BooleanIszero,LongPnLongLasttenid) {inti = 0; /* Judge whether the beginning is 0*/if(!iszero)
{Tenid = N/2;
i = 1; }/* is greater than and equal to 5 odd digits palindrome number Generation method * *if(n = = 3)
{//System.out.println ("NT" +nexttenid); Threedigit (PN, Lasttenid,false, Tenid); return; }/* is greater than and equal to more than 6 parity number generation method * *else if(n = = 4)
{//System.out.println ("LId:::" + (2*tenid-lasttenid-1)); Fourdigit (PN, 2 * tenid-lasttenid-1, Lasttenid,false, Tenid); return; } for(; I <= 9;) {Longresult = PN;if(!iszero) {PN = (Long) (I * MATH.POW (n-1) + i);
result = PN;
Lasttenid = 0; }Else{result = = (Long) (I * MATH.POW (2 * tenid-lasttenid) + i * MATH.POW (Lasttenid));
System.out.println ("res" +result);
}//if (!iszero) System.out.println ("I" +i);
++i; Odddigitpalindromenumber (N-2, Tenid,true, result, Lasttenid + 1); }/* is greater than or equal to 6 odd digit palindrome number * *Public voidFire () {odddigitpalindromenumber (6, 0,false, 0, 0); }
}