Skip to main content

KAPREKAR NUMBER

PROGRAM : KAPREKAR NUMBER

Kaprekar number  is a non-negative integer, the representation of whose square  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. And if second splitted part have only 0s then it is not kaprekar number for example 100*100=10000 splitted part is 10+000 thus second part have 0s only

Some Examples are: 999
999*999=998001=>998+001=999
1, 9, 45, 55, 99, 297, 703, 999, 2223, 2728, 4879, 4950, 5050, 5292, 7272, 7777, 9999, 17344, 22222, 38962, 77778, 82656, 95121, 99999, 142857, 148149, 181819, 187110 
are some examples of Kaprekar Number

SYNTAX

import java.io.*;
class kaprekar
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n;int d=0,c=0;int n1;
        System.out.println("ENTER A NUMBER");
        n=Integer.parseInt(br.readLine());
        int square=n*n;int d1=0,d2=0;n1=n;
        int sq=square;
        String s=Integer.toString(square);
        while(sq!=0)
        {
            d=sq%10;
            c++;
            sq=sq/10;
        }
    
    if(c%2==0)
    {
        int x=(int)Math.pow(10,c/2);
        d2=(square%(int)x);
        d1=square/(int)x;
        System.out.print(d1+"+"+d2);
        if(d2==0)System.out.println("No The Number is not kaprekar Number\n As the second part of its square have only 0s");
        else if((d1+d2)==(n))
        System.out.print("="+(n)+"\nYES The Number is kaprekar Number");
        else
        System.out.println("!="+(n)+"\nNo The Number is not kaprekar Number");
    }
    else
    {   int y=(int)Math.pow(10,(c+1)/2);
        d2=(square%(int)y);
        d1=square/(int)y;
        System.out.print(d1+"+"+d2);
        if(d2==0)System.out.println(" \nNo The Number is not kaprekar Number\n As the second part of its square have only 0s");
        else if((d1+d2)==(n))
        System.out.print("="+(n)+"\nYES The Number is kaprekar Number");
        else
        System.out.print("!="+(n)+"\nNo The Number is not kaprekar Number");
}
}
}


SCREENSHOTS




Comments

Popular posts from this blog

LUCKY NUMBER

PROGRAM : LUCKY NUMBER QUESTION: Consider the sequence of natural numbers. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 …………………………………. Removing every second number produces the sequences 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 …………………………. Removing every third number produces the sequences 1, 3, 7, 9, 13, 15, 19, 21, 25 …………………………. This process continues indefinitely by removing the fourth, fifth…and so on, till after a fixed number of steps, certain natural numbers remain indefinitely. These are known as  Lucky Numbers . Write a program to generate and print lucky numbers less than a given number N. SAMPLE INPUT :   N = 10 OUTPUT :   The Lucky numbers less than 10 are:     1     3     7 SAMPLE INPUT :   N = 25 OUTPUT :   The Lucky numbers less than 25 are:     1     3  ...

SMITH NUMBER

PROGRAM: SMITH NUMBER A   Smith number  is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 58, 85, 94, 121 ……………….. For Example 58=> 5+8=13 2+(2+9) of 29 =13 Since sum of digits=sum of digits of prime factors 58 is a SMITH NUMBER SYNTAX: import java.io.*; class smith_no { static int sum,sum1;     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int c=0;         System.out.println("Enter a Number");         n=Integer.parseInt(br.readLine());         int n1=n;         while(n1!=0){         int d=n1%10;         sum1+=d; ...

Disarium Number

AJ Java Programs Program 4: Disarium Number A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number. For example  135 is a DISARIUM (Workings 1 1 +3 2 +5 3  = 135, some other  DISARIUM  are 89, 175, 518 etc) Syntax: import java.io.*; class disarium {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,n1,n2,c=0,sum=0,d=0;         System.out.println("Enter a Num");         n=Integer.parseInt(br.readLine());         n2=n1=n;         while(n2!=0)         {             n2=n2/10;             c++;         }       ...