1. Write a program in Java to check whether two numbers are amicable or not.
Amicable Number: If two numbers are such that the sum of the perfect divisors of one number is equal to
the other number and
the sum of the perfect divisors of the other number is equal to the first number, then the numbers are
called Amicable Numbers.
Example : 220 and 284.
import [Link].*;
public class amicable
public static void main (String args[])
Scanner sc = new Scanner([Link]);
[Link]("Enter the first number ");
int n1=[Link]();
[Link]("Enter the first number ");
int n2=[Link]();
int sum1=0,sum2=0,rem=0;
for (int i=1; i<n1; i++)
{ if(n1%i==0)
sum1=sum1+i;
for (int i=1; i<n2; i++)
{ if(n2%i==0)
sum2=sum2+i;
}
if (n1==sum2 && n2==sum1)
[Link](n1+","+n2+"are amicable number");
else
[Link](n1+","+n2+"are not amicable number");
import [Link].*;
public class palprime
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("Enter n ");
int n=[Link]();
int count=0,rem=0,rev=0,n1=n;
for(int i=1;i<=n;i++)
{
if(n%i==0)
{
count++;
}
}
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
if(count==2 && n1==rev)
[Link](n1+"is a palprime number");
else
[Link](n1+"is not a palprime number");
}
}
import [Link].*;
public class super_palindrome
{
public static void main(String args[])
{
Scanner sc=new Scanner([Link]);
[Link]("Enter n");
int n=[Link]();
int sq=n*n;
int rem=0,rev=0,rev1=0,n1=n,sq1=sq;
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
while(sq>0)
{
rem=sq%10;
rev1=rev1*10+rem;
sq=sq/10;
}
if(n1==rev && sq1==rev1)
[Link](n1+"is a super palindrome number");
else
[Link](n1+"is not a super palindrome number");
}
}
/* A Magic number is a number or not. A number is said to be magic number if sum of the digits is
calculated
* repeatedly till a single digit is obtained and if that single digit number is equal to 1.
Example:n=199
1+9+9=19
1+9=10
1+0=1
output: 199 is a Magic number*/
import [Link].*;
public class magic_number
{
public static void main (String args[])
{ Scanner sc= new Scanner ([Link]);
[Link]("Enter the number ");
int n=sc. nextInt();
int sum=0,rem=0,n1=n;
while(n>9)
{
sum=0;
while(n>0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
n=sum;
}
if(n==1)
[Link](n1+" is a Magic number");
else
[Link](n1+" is not a Magic number");
}}