java program on kaprekar's number

Download Java Program on Kaprekar's Number

If you can't read please download the document

Upload: utkarsh-singh

Post on 22-Oct-2015

23 views

Category:

Documents


4 download

DESCRIPTION

Java Program

TRANSCRIPT

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. ");}}}}/ /