It is a number whose square, when divided into two parts, the sum of parts is equal to the original number
For Example 45–>(45)^2= 2025–>Now when we divide this number into two parts(20 and 25), their sum is 20+25=45. So It is a kaprekar number.
For string programs click the given link
https://java4school.com/string-programs-part-5
Write a program to accept a number and check whether it is a kaprekar number or not.
import java.io.*;
class karpekar //sum of digits in its square is the number itself e.g., 45
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int num=Integer.parseInt(br.readLine());
int n=num;
int sq=num*num;
int count=0;
while(n!=0)
{
n=n/10;
count++;
}
int sq1=(int)(sq/Math.pow(10,count));
int sq2=(int)(sq%Math.pow(10,count));
if(sq1+sq2==num)
{
System.out.println("It is a karpekar number");
}
else
{
System.out.println("It is not a karpekar number");
}
}
}
Output:
Enter a number
45
It is a karpekar number
For videos to learn java programming click the given link
https://youtu.be/TRm9r4gFTho