Forked from anonymous/gist:33d7546492974c28edd5825177879a70
Last active
December 13, 2016 15:51
-
-
Save sim642/459bcadcdbc372ebbf47e32e88b0b10d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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