×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
Write a program to display the possible sum Consecutive numbers to developed a given number. Check A Date Valid or not
Kaprekar number - Java
45593    Arnab De    25/06/2018

Kaprekar number

Write a program to check a number is Kaprekar number or not. A Kaprekar number for a given base is a non-negative integer, the representation of whose square in that base can be split into two parts that add up to the original number again. For instance, 45 is a Kaprekar number, because 452 = 2025 and 20+25 = 45.



import java.util.*;
class Kaprekar
{
    public static void main()
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number:");
        int num = sc.nextInt();
        int p = 0;
        int digit=0,sq,sum=0;
        sq = num*num;
        p=sq;
        while(sq>0)
        {
            digit++;
            sq=sq/10;
        }
        int k=(int)Math.pow(10,(digit/2));
        while(p>0)
        {
            sum=sum+(p%k);
            p=p/k;
        }
        if(sum==num){
        System.out.println("Is a kaprekar number");
        }
        else{
        System.out.println("Is not a kaprekar number");
        }
    }
}
        
softetechnologies

Output:
Enter the number:
9 Is a kaprekar number

Write a program to display the possible sum Consecutive numbers to developed a given number. Check A Date Valid or not
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
03/11/2021: Hu... U can do it in easy way also.... But this is also right.... GOOD JOB
By: Hanta Killer [hanukumar2007@gmail.com]
Thank You very much
02/02/2023: 297 is a Kaprekar no. but above code will show that its not.
By: ashish [ashish_rc@ymail.com]
Rabindranath Tagore
The highest education is that which does not merely give us information but makes our life in harmon
Rabindranath Tagore
1147
83.06
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54499
25/06/2018     45593
01/01/2018     43927
28/06/2017     41444
02/08/2017     40536
01/08/2017     34527
06/07/2017     34306
15/05/2017     33546
11/09/2018     30824
14/07/2017     30327
softetechnologies