-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAmicable_Number.java
More file actions
26 lines (24 loc) · 749 Bytes
/
Amicable_Number.java
File metadata and controls
26 lines (24 loc) · 749 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
import java.util.*;
class Amicable_Number {
public static void main(String Args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter two numbers");
System.out.print("Enter first number: ");
int n1 = sc.nextInt();
System.out.print("Enter second number: ");
int n2 = sc.nextInt();
int i, s1 = 0, s2 = 0;
for (i = 1; i < n1; i++) {
if (n1 % i == 0)
s1 = s1 + i;
}
for (i = 1; i < n2; i++) {
if (n2 % i == 0)
s2 = s2 + i;
}
if (s1 == n2 && s2 == n1)
System.out.println("Amicable Number");
else
System.out.println("Not an Amicable Number");
}
}