You are viewing a single comment's thread. Return to all comments →
Java
public static void kaprekarNumbers(int p, int q) { boolean found = false; while (p <= q) { String sq = String.valueOf((long) p * p); String left = sq.substring(0, (int) (sq.length() / 2)); String right = sq.substring((int) (sq.length() / 2)); int l = Integer.valueOf(left.equals("") ? "0" : left); int r = Integer.valueOf(right); if (l + r == p) { found = true; System.out.print(p + " "); } p++; } if (!found) { System.out.print("INVALID RANGE"); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Modified Kaprekar Numbers
You are viewing a single comment's thread. Return to all comments →
Java