Write a class Automorphic to check whether a number is Automorphic or not using function with the help of a method
Int digit(int n)
Solution
import java.io.*;
/**
* class Automorphic
*
*/
public class Automorphic
{
int digits(int n)
{
int c,p,k;c=0;k=0;
while(n!=0)
{
k=n/10;
c=c+1;
n=k;
}
return(c);
}
public static void main(String args[])throws IOException
{
InputStreamReader read =new InputStreamReader(System.in);
BufferedReader in =new BufferedReader(read);
int m,n,p,b;
double r;
r = 0;
Automorphic ob= new Automorphic();
System.out.println("Enter your no.");
n=Integer.parseInt(in.readLine());
m= n;
p= m * m;
b=ob.digits(n);
r=p % (Math.pow(10,b));
if(m==r)
System.out.println(m + " is an Automorphic no.");
else
System.out.println(m + " is not an Automorphic no.");
}
}
Output;
Enter your no.
625
625 is an Automorphic no.
Enter your no.
525
525 is not an Automorphic no.
No comments:
Post a Comment