public class RuntimeConstantPoolOOM { public static void main(String [] args) { int k=10; Palindrome(k); } public static void Palindrome(int k){ if(k<0) return; int x=0; int count=0; while(x<k) { // Convert numbers to strings String s = Integer.toBinaryString(x); if (isPalindrome (s)) { count++; } x++; } System.out.println(count); } // Determine if it is a palindrome public static boolean isPalindrome(String s){ for(int i=0;i<s.length()/2;i++){ if(s.charAt(i)!=s.charAt(s.length()-i-1)) return false; } return true; } }
During the written test, I read the wrong question, I thought it was printing all the situations, and I was always tangled. In fact, it was just the number of output.