answersLogoWhite

0

import java.io.*;

class kaprekar

{

public static void main(String args[])throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter any number");

int n=Integer.parseInt(br.readLine());

int t=n,count=0;

while(n!=0)

{

n=n/10;

count++;

}

int s=t*t;

int p=(int)Math.pow(10,count);

int ld=s%p;

int minus=s-ld;

int fd=minus/p;

int sum=fd+ld;

if(sum==t)

{

System.out.println("Kaprekar Number");

}

else

{

System.out.println("Not a Kaprekar number");

}

}

}

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran

Add your answer:

Earn +20 pts
Q: How do you code a program to find kaprekar number?
Write your answer...
Submit
Still have questions?
magnify glass
imp