We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Modified Kaprekar Numbers
  5. Discussions

Modified Kaprekar Numbers

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

    You are viewing a single comment's thread. Return to all comments →

  • yash_cs1994
    2 months ago+ 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");
            }
        }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy