-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmicable.java
More file actions
34 lines (30 loc) · 757 Bytes
/
Amicable.java
File metadata and controls
34 lines (30 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.*;
class Amicable
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter first number");
int a=sc.nextInt();
System.out.println("Enter second number");
int b=sc.nextInt();
int s1=0;
int s2=0;
for(int x=1;x<a;x++){
if(a%x==0){
s1+=x;
}
}
for(int x=1;x<b;x++){
if(b%x==0){
s2+=x;
}
}
if(s1==b && s2==a){
System.out.println("The pair ("+a+","+b+") is an Amicable Pair");
}
else{
System.out.println("The pair ("+a+","+b+") is not an Amicable Pair");
}
}
}