Program to Generate or Check for Kaprekar Numbers by Ashutosh

download Program to Generate or Check for Kaprekar Numbers by Ashutosh

of 1

description

Program to generate Kaprekar Numbers

Transcript of Program to Generate or Check for Kaprekar Numbers by Ashutosh

// Program to generate or check for Kaprekar Numbers import java.math.BigInteger; /** * * @author Ashutosh * La Martiniere College, Lucknow */ public class Kaprekar { public static boolean check(BigInteger n) { String str = n.multiply(n).toString() ; int mid = str.length() >> 1 ; BigInteger left = new BigInteger(str.substring(0, mid)) ; BigInteger right = new BigInteger(str.substring(mid)) ; return (left.add(right).equals(n)) ; } public static void main(String[] args) { BigInteger q = new BigInteger("50000000") ; System.out.println("THE KAPREKAR NUMBER ARE : ") ; System.out.println(1) ; long count = 1 ; for (BigInteger i = BigInteger.valueOf(5) ; i.compareTo(q)