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
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.