Posted by: Sourav | June 27, 2014

Kaprekar Number in Java


import java.util.Scanner;
class kaprakar_number
{
public static void main(String args[])
{
    
    int n;
    Scanner in = new Scanner(System.in);
        
        System.out.println(“input the number”);
        
        n = Integer.parseInt(in.nextLine());
    int temp,k,a=0,r,rem,quo;
     
     temp=n;
     k=n*n;
          
          
            while(n>0)
            {
                r=n%10;
                a++;
                n=n/10;
            }
           // System.out.println(“a is “+a);
            rem=k%((int)Math.pow(10,a));
            quo=k/((int)Math.pow(10,a));
              
     if((rem+quo)==temp)
            System.out.println(“kaprakar number”);
            else
              System.out.println(” not kaprakar number”);
            }
        }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: