Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


soumyadeep
kaprekar
1 Answer(s)      3 years and 10 months ago
Posted in : Java Beginners


wap to input a number . check whether the no. is kaprekar or not?


Advertisement
View Answers

February 19, 2011 at 5:43 PM


Java Check Kaprekar Number

import java.util.*;
class CheckkaprekarNumber{
    public static void main(String args[])throws Exception{
        Scanner input=new Scanner(System.in);
        System.out.print("Enter number: ");
        int x=input.nextInt();
        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--;
                }
                int r=0;
                while(rev > 0){
                    r=r*10+rev%10;
                    rev=rev/10;
                    }
                    if((r+no)==x){
                        System.out.println("It is a Kaprekar No. ");
                        }
                        else{
                            System.out.println("It is not a Kaprekar No. ");
                            }
                            }
                            }


Related Tutorials/Questions & Answers:
kaprekar
kaprekar   wap to input a number . check whether the no. is kaprekar
kaprekar
kaprekar   wap to input a number . check whether the no. is kaprekar
Advertisements
kaprekar
kaprekar   wap to input a number . check whether the no. is kaprekar
Advertisements
 

 

 

DMCA.com