An Efficient Kaprekar Number
For string programs click the given link https://wordpress-343193-1101484.cloudwaysapps.com/string-programs-part-5
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
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
Related Posts
Continue learning with these related articles

String Methods in Java for ICSE Class 10: 25 Output Questions with Answers
ICSE Class 10 Computer Applications practice on String class methods: length, charAt, indexOf, lastIndexOf, substring, replace, trim, compareTo, equals and more, with 25 board-style output questions and step-by-step answers.

Special Number Programs in Java for ICSE: Armstrong, Spy, Neon, Disarium, Pronic and More
Every special number asked in ICSE Computer Applications – prime, perfect, Armstrong, palindrome, automorphic, neon, spy, Niven, duck, buzz, Disarium, special and pronic numbers – with definitions, examples and one complete Java program that checks them all.

Math Library Methods in Java for ICSE Class 9 (with Outputs)
ICSE Class 9 Computer Applications notes on the Java Math class: sqrt, cbrt, pow, abs, max, min, ceil, floor, round, rint and random, with return types, tricky negative-number outputs and Java expressions for formulas.