
wap to input a number . check whether the no. is kaprekar or not?

Java Check Kaprekar Number
import java.util.*;
class CheckkaprekarNumber{
public static void main(String args[])throws Exception{
Scanner input=new Scanner(System.in);
System.out.print("Enter number: ");
int x=input.nextInt();
int num=x*x,no=x,digit=0;
int rev=0;
while(no>0){
digit++;
no=no/10;
}
no=num;
while(digit > 0){
rev=rev*10+no%10;
no=no/10;
digit--;
}
int r=0;
while(rev > 0){
r=r*10+rev%10;
rev=rev/10;
}
if((r+no)==x){
System.out.println("It is a Kaprekar No. ");
}
else{
System.out.println("It is not a Kaprekar No. ");
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.