• + 0 comments

    My Java Solution

        public static void kaprekarNumbers(int p, int q) {
        // Write your code here
        boolean Found=false;
        for(int i=p;i<=q;i++){
           
            int temp=i;
            String str=Integer.toString(temp);
            int len=str.length();       
            BigInteger I=new BigInteger(str);
            BigInteger N=I.multiply(I);
            String str2=N.toString();
            int len2=str2.length();
            if(len2==1){
                if(N.equals(I)){
                        System.out.print(i+" ");
                Found=true;
                }
            }else{
            int num1=Integer.parseInt(str2.substring(0, len2-len));
            int num2=Integer.parseInt(str2.substring(len2-len, len2));
            if((num1+num2)==i){
                System.out.print(i+" ");
                Found=true;
            }
            }}
            if(!Found){
                System.out.println("INVALID RANGE");
            }
        }