下面是我的代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in .nextInt();
int flag = 0;
int[] test = new int[t];
while(in.hasNext()){
test[flag] = in.nextInt();
flag++;
if (flag==t)break;
}
for (int i = 0; i < t; i++){
String bo = huiwen(test[i]);
System.out.println(bo);
}
}
public static String huiwen(int in) {
String flag = "true";
StringBuilder str = change(in);
String sm = str.toString();
String st = str.reverse().toString();
for (int i = 0; i< st.length();i++){
if(sm.charAt(i) != st.charAt(i)) {
flag = "false";
break;
}
}
return flag;
}
public static StringBuilder change(int i) {
StringBuilder str = new StringBuilder();
while(i!=0){
str.insert(0, i % 2);
i = i/2;
}
return str;
}
}