You are viewing a single comment's thread. Return to all comments →
public static void kaprekarNumbers(int p, int q) { // Write your code here int value = 0; String num; int sum = 0; int count = 0; for(long i=p; i<=q; i++){ value = String.valueOf(i*i).length(); num = i*i+""; sum = Integer.parseInt(num.substring(0,value/2) == "" ? "0":num.substring(0,value/2)) + Integer.parseInt(num.substring(value/2,value)); if(sum == i){ count++; System.out.print(i+" "); } sum = 0; } if(count <=0){ 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 →