You are viewing a single comment's thread. Return to all comments →
My solution in java whitout using any String or StringBuilder method. Passes all test cases.
class Result { public static void kaprekarNumbers(int p, int q) { int digitsOfI = 0; long square = 0; long right = 0; long left = 0; boolean foundNumber = false; for(int i = p; i <= q; i++){ digitsOfI = (int) (Math.log10(i) + 1); square = (long) Math.pow(i, 2); right = square % (long) Math.pow(10, digitsOfI); left = square / (long) Math.pow(10, digitsOfI); if(left + right == i){ foundNumber = true; System.out.print(i + " "); } } if(foundNumber == false) System.out.println("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 →
My solution in java whitout using any String or StringBuilder method. Passes all test cases.