Checking that given number is automorphic or not by lakshmankablog
package mypro;
import java.util.Scanner;
public class AutoMorphicNumber {
public static void main(String[] args) {
Scanner obj= new Scanner(System.in);
System.out.println("Enter the number for checking is an automorphic or not ");
int n= obj.nextInt();
int n2,len=0,len2,rem,rem1,rev;
int restn=n;
n2= n*n;
while(n>0) {
len++;
n = n/10;
}
// System.out.println(len);
len2=len; rev=0;
for(int i= 0; i<len; i++) {
rem = n2 % 10;
rev= rev*10+rem;
n2 = n2/10;
}
// System.out.println(rev);
int revofrev = 0;
for(int j=0; j<len2; j++) {
rem1= rev%10;
revofrev = revofrev*10+rem1;
rev = rev/10;
}
// System.out.println(revofrev);
if(restn==revofrev) {
System.out.println("The number "+restn+" "+" is automorphic ");
}
else {
System.out.println("The number is not automorphic ");
}
}
}
Comments
Post a Comment