Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2016 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/33d7546492974c28edd5825177879a70 to your computer and use it in GitHub Desktop.
Save anonymous/33d7546492974c28edd5825177879a70 to your computer and use it in GitHub Desktop.
public class Ch5_q7 {
public static void main(String[] args) {
int[] mateArray = new int[21];
int counter = 1, starter = 1;
mateArray[0] = 0;
while (counter < 21) {
if (starter != dividerSum(starter) && starter == dividerSum(dividerSum(starter))) {
if (starter != mateArray[counter-1]) {
mateArray[counter] = starter;
mateArray[counter+1] = dividerSum(starter);
counter += 2;
}
}
starter++;
}
for (int i = 1; i < 21; i += 2) {
System.out.println(mateArray[i] + " and " + mateArray[i + 1] + " are friendly numbers");
}
}
public static int dividerSum(int num1) {
int num2 = 0;
for (int index = 1; index < num1; index++) {
if ((num1 % index) == 0) {
num2 += index;
}
}
return num2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment