0% found this document useful (0 votes)
88 views

Java Program On Kaprekar's Number

This program checks if a number is a Kaprekar number by squaring the input number, splitting the square into two parts by placing digits from right to left of the square into one part and left to right into another part, adding those parts, and checking if the sum equals the original number. The user inputs a number, it is squared and split into two parts by placing digits into reverse order in one part and normal order in another, those parts are summed and checked against the original number, and the program outputs whether it is or isn't a Kaprekar number.

Uploaded by

Utkarsh Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views

Java Program On Kaprekar's Number

This program checks if a number is a Kaprekar number by squaring the input number, splitting the square into two parts by placing digits from right to left of the square into one part and left to right into another part, adding those parts, and checking if the sum equals the original number. The user inputs a number, it is squared and split into two parts by placing digits into reverse order in one part and normal order in another, those parts are summed and checked against the original number, and the program outputs whether it is or isn't a Kaprekar number.

Uploaded by

Utkarsh Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

11. Write a program to check whether a number is a Kaprekar No. ornot.

( The repr esentation of whose square in that base can be splitinto two parts that add up t o the original number again. Forinstance, 45 is a Kaprekar number, because 45 = 2 025 and20+25 = 45. )Code: import java.io.*; class Kaprekar{ public static void main(String args[])throws IOException {InputStreamReader ir=new InputStreamReader(System.in); BufferedReader br=new BufferedReader (ir); System.out.println("Enter No. :"); int x=Integer.parseInt(br.readLine()); int num=x*x,no=x,digit=0;;int rev=0; while(no>0) {digit++;no=no/10;}no=num;while(digit > 0){rev=rev*10+no%10;no=no/10;digit--;}in t r=0;while(rev > 0){r=r*10+rev%10;rev=rev/10;}if((r+no)==x){System.out.print("I t is a Kaprekar No. ");}else{System.out.print("It is not a Kaprekar No. ");}}}}/ /

You might also like