public class Duichengshu {
public static void main(String[] args)
{
Boolean isOK1 = isDCNumber(3);
Boolean isOK2 = isDCNumber(2332);
Boolean isOK3 = isDCNumber(34143);
Boolean isOK4 = isDCNumber(341243);
}
public static boolean isDCNumber(int number){
String numStr = String.valueOf(number);
if(numStr.length()==1){
return true;
}
if(numStr.length()%2==0){
String front = numStr.substring(0, numStr.length()/2);
String end = numStr.substring(numStr.length()/2, numStr.length());
byte[] bytes = end.getBytes();
byte[] newByte = new byte[128];
for(int i=0;i<bytes.length;i++)
{
newByte[i] = bytes[bytes.length-1-i];
}
String reverseEnd = new String(newByte).trim();
if(front.equals(reverseEnd)){
return true;
}
}else{
String front = numStr.substring(0, numStr.length()/2);
String end = numStr.substring(numStr.length()/2+1, numStr.length());
byte[] bytes = end.getBytes();
byte[] newByte = new byte[128];
for(int i=0;i<bytes.length;i++)
{
newByte[i] = bytes[bytes.length-1-i];
}
String reverseEnd = new String(newByte).trim();
if(front.equals(reverseEnd)){
return true;
}
}
return false;
}
}
public static void main(String[] args)
{
Boolean isOK1 = isDCNumber(3);
Boolean isOK2 = isDCNumber(2332);
Boolean isOK3 = isDCNumber(34143);
Boolean isOK4 = isDCNumber(341243);
}
public static boolean isDCNumber(int number){
String numStr = String.valueOf(number);
if(numStr.length()==1){
return true;
}
if(numStr.length()%2==0){
String front = numStr.substring(0, numStr.length()/2);
String end = numStr.substring(numStr.length()/2, numStr.length());
byte[] bytes = end.getBytes();
byte[] newByte = new byte[128];
for(int i=0;i<bytes.length;i++)
{
newByte[i] = bytes[bytes.length-1-i];
}
String reverseEnd = new String(newByte).trim();
if(front.equals(reverseEnd)){
return true;
}
}else{
String front = numStr.substring(0, numStr.length()/2);
String end = numStr.substring(numStr.length()/2+1, numStr.length());
byte[] bytes = end.getBytes();
byte[] newByte = new byte[128];
for(int i=0;i<bytes.length;i++)
{
newByte[i] = bytes[bytes.length-1-i];
}
String reverseEnd = new String(newByte).trim();
if(front.equals(reverseEnd)){
return true;
}
}
return false;
}
}