import java.util.*;
public class assignment_8
{
void check(int n1, int n2)
{
int sum = 0;
int s = 0;
for(int i = 1;i<n1;i++)
{
if(n1%i==0)
{
sum = sum +i;
}
}
for(int j = 1;j<n2;j++)
{
if(n2%j==0)
s= s+j;
}
if(sum == n2 && s==n1)
System.out.println("The pair of two numbers " + n2+" and " + n2 +" is amicable ");
else
System.out.println("The pair of two numbers " + n2 +" and " + n2 +" is not amicable");
}
void check(int n)
{
int c = 0;
int c1 = 0;
int p = n;
for(int a = 1;a<=n;a++)
{
if(n%a==0)
c++;
}
while(n!=0)
{
int r = n%10;
c1=c1*10 + r;
n = n/10;
}
if(c==2 && c1==p)
System.out.println(p+ " is a palprime number");
else
System.out.println(p+ " is not a palprime number");
}
public static void main(String []args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number to be checked amicable or not");
int num1= sc.nextInt();
System.out.println("Enter the second number to be checked amicable or not");
int num2= sc.nextInt();
System.out.println("Enter the number to be checked palprime or not");
int num3= sc.nextInt();
assignment_8 obj = new assignment_8();
obj.check(num1,num2);
obj.check(num3);
}
}
public class assignment_8
{
void check(int n1, int n2)
{
int sum = 0;
int s = 0;
for(int i = 1;i<n1;i++)
{
if(n1%i==0)
{
sum = sum +i;
}
}
for(int j = 1;j<n2;j++)
{
if(n2%j==0)
s= s+j;
}
if(sum == n2 && s==n1)
System.out.println("The pair of two numbers " + n2+" and " + n2 +" is amicable ");
else
System.out.println("The pair of two numbers " + n2 +" and " + n2 +" is not amicable");
}
void check(int n)
{
int c = 0;
int c1 = 0;
int p = n;
for(int a = 1;a<=n;a++)
{
if(n%a==0)
c++;
}
while(n!=0)
{
int r = n%10;
c1=c1*10 + r;
n = n/10;
}
if(c==2 && c1==p)
System.out.println(p+ " is a palprime number");
else
System.out.println(p+ " is not a palprime number");
}
public static void main(String []args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the first number to be checked amicable or not");
int num1= sc.nextInt();
System.out.println("Enter the second number to be checked amicable or not");
int num2= sc.nextInt();
System.out.println("Enter the number to be checked palprime or not");
int num3= sc.nextInt();
assignment_8 obj = new assignment_8();
obj.check(num1,num2);
obj.check(num3);
}
}
No comments:
Post a Comment