Hey, in this post we will learn about Amicable Number and we will learn also that how to write a java program to check Amicable Number.

Amicable numbers come in a pair. So whenever we write an Amicable number we write them in a pair. The smallest Amicable Number pair is (220, 284).

Let’s understand what is an amicable number. **Amicable numbers** are two different numbers so related that the sum of the proper divisors of each is equal to the other number.

For 220 the proper divisors are 1, 2 ,4, 5, 10, 11, 20, 22, 44, 55 and 110

And For 284 the proper divisors are 1, 2, 4, 71 and142 .

let’s make a sum of 220 proper divisors : 1+2 + 4 + 5 + 10+ 11 + 20 + 22 + 44 + 55 = 284 .

And the sum of 284 proper divisors : 1 + 2 + 4 + 71 +142 = 220 .

More Explanation in a picture that will help you to understand more

So let’s write a java program to check Amicable Numbers.

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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
package com.practicehouse; import java.util.Scanner; public class AmicableNumber { public static void main(String[] args) { int firstNumber, secodNumber; Scanner scanner = new Scanner(System.in); System.out.println("Enter two Numbers: "); firstNumber = scanner.nextInt(); secodNumber = scanner.nextInt(); boolean flag = checkAmicableOrNot(firstNumber, secodNumber); if (flag) { System.out.println("The numbers are amicable"); } else { System.out.println("The numbers are not amicable"); } } static boolean checkAmicableOrNot(int firstNumber, int secondNumber) { int s = 0, i; for (i = 1; i < firstNumber; i++) { if (firstNumber % i == 0) { s = s + i; } } if (s == secondNumber) { s = 0; for (i = 1; i < secondNumber; i++) { if (secondNumber % i == 0) { s = s + i; } } if (s == firstNumber) return true; else return false; } return false; } } |

Sample Output:

1 2 3 4 5 6 7 8 9 |
Enter two Numbers: 220 284 The numbers are amicable Enter two Numbers: 234 987 The numbers are not amicable |

The first ten amicable pairs are:

(220, 284), (1184, 1210), (2620, 2924), (5020, 5564), (6232, 6368),

(10744, 10856), (12285, 14595), (17296, 18416), (63020, 76084) and (66928, 66992).

I hope you have learned about Amicable Numbers and you also learned that how to write a java program to check the numbers are amicable or not. Keep Learning best wishes to you.

Thank you so much for being here. We appreciate your presence. Inspire us to do more by comment’s or share this knowledge for who wants to learn.

**Java – PHP – Python – Dart – Flutter – MySql – Spring – Hibernate – JavaScript – jQuery – BootStrap 4 – CSS – HTML**

I love to explore new technologies. If you like my tutorials please share your thoughts about my work.

Check out my YouTube Channel For Video Tutorials.

To Hire Me Please Contact Me Through Social Media or https:www.amialif.com

If you want to help others by doing donation please Help Them.

You also can connect with me via social media. Thanks

## Leave a Reply