write a program in JAVA for the given number is Adam number or not.
Answers
Answered by
24
ADAM'S NUMBER
EXAMPLE= LIKE 12
REVERSE =21
SQUARE OF REVERSE =441
SQUARE OF ORIGINAL (12)=144
BOTH THE SQUARE ARE REVERSE OF EACH OTher
program:
int n= INPUT number,rev,rev1,d,d1;
for(int i=n;i>0;i=i/10)
{
d=n%10;
rev= rev*10+d;
}
int sn=n*n;
for (int i=sn;i>0;i=i/10)
{
d1=n%10;
rev1=rev1*10+d1;
}
rev=rev*rev;
if(rev==rev1)
{
System.out.println("ADAMS NUMBER");
}
else
{
System.out.println("not a ADAMS NUMBER");
}
EXAMPLE= LIKE 12
REVERSE =21
SQUARE OF REVERSE =441
SQUARE OF ORIGINAL (12)=144
BOTH THE SQUARE ARE REVERSE OF EACH OTher
program:
int n= INPUT number,rev,rev1,d,d1;
for(int i=n;i>0;i=i/10)
{
d=n%10;
rev= rev*10+d;
}
int sn=n*n;
for (int i=sn;i>0;i=i/10)
{
d1=n%10;
rev1=rev1*10+d1;
}
rev=rev*rev;
if(rev==rev1)
{
System.out.println("ADAMS NUMBER");
}
else
{
System.out.println("not a ADAMS NUMBER");
}
anuj:
this is the snap of the coding
class Main
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt(),rev,n1,n2,n3;
if(n>=1 && n<=100000000)
{
StringBuilder sb=new StringBuilder(Integer.toString(n)).reverse();
rev=Integer.parseInt(sb.toString());
n1=n*n;
n2=rev*rev;
StringBuilder sb1=new StringBuilder(Integer.toString(n2)).reverse();
n3=Integer.parseInt(sb1.toString());
if(n1==n3)
{
System.out.println("ADAM");
}
else{
System.out.println("NOT ADAM");
}
}
}
}
Similar questions