Showing posts with label kaprekar-number. Show all posts
Showing posts with label kaprekar-number. Show all posts

Friday, July 31, 2020

Write a program to input a number and check whether it is Kaprekar’s Number or not? (297=297*297=88209=88+209=297)

64)  Write a program to input a number and check whether it is Kaprekar’s Number or not? (297=297*297=88209=88+209=297)


import java.util.*;
public class Kaprekars
{
    public static void main(String args[ ])
   {
              Scanner sc = new Scanner (System.in);
              System.out.println("Enter a number");
              int a = sc.nextInt();
              int k = a;
              int c = 0;
              while(k>0)
              {
                  k=k/10;
                  c++;
              }
              int p = a*a;
              int x = (int)Math.pow(10,c);
              int m = p%x;
              int n = p/x;
              if((m+n)==a)
              {
                  System.out.println("Entered number is a KAPREKAR's Number");
              }
              else
              {
                  System.out.println("Entered number is a KAPREKAR's Number");
              }
   }               
}

Output : 




 jhvghvgk ;nkjn ,nkjhj