You are viewing a single comment's thread. Return to all comments →
i dont know whats wrong with my code?
public static void kaprekarNumbers(int p, int q) { // Write your code here for (int i = p; i < q; i++) { if (checkResult(i)) System.out.print(i + " "); } } private static boolean checkResult(int n) { int temp = n; n = n * n; int c = count(n); int length = c / 2; // System.out.println(length); String r = ""; while (length > 0) { int d = n % 10; r = d + r; n = n / 10; length--; } int res = Integer.parseInt(r) + n; if (res == temp) return true; else return false; } private static int count(int n) { int c = 0; do { c++; n = n / 10; } while (n != 0); return c; }
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
i dont know whats wrong with my code?