Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Java check Automorphic numbers
Sponsered Links
Categories
Sponsered Links

Java check Automorphic numbers

Automorphic number are the numbers whose square "ends" in the same digits as number itself. For example, 52 = 25, 762 = 5776, and 8906252 = 793212890625, so 5, 76 and 890625 are all automorphic numbers. Here we are going to check whether the number enetered by the user is automorphic or not.

import java.math.*;
    import java.util.*;
    class AutomorphicNumber{
        static int d=10;
        public static void main(String args[]){
            System.out.print("Enter any number :");
            Scanner input=new Scanner(System.in);
            int n=input.nextInt();
            if(d>=n){
            if ((n*n) % d == n){
            System.out.println("Automorphic Number");
            }
            else{
            System.out.println("Not Automorphic Number");
                }
            }
            else if(d<=n){
            d=d*10;
            if ((n*n) %d==n){
            System.out.println("Automorphic Number");
            }
            else{
            System.out.println("not an automorphic number");
            }
            }   
          }
        }

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved