mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-20 18:24:49 +08:00
Format code with prettier (#3375)
This commit is contained in:
@ -20,7 +20,6 @@ package com.thealgorithms.maths;
|
||||
public class AmicableNumber {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
AmicableNumber.findAllInRange(1, 3000);
|
||||
/* Res -> Int Range of 1 till 3000there are 3Amicable_numbers These are 1: = ( 220,284) 2: = ( 1184,1210)
|
||||
3: = ( 2620,2924) So it worked */
|
||||
@ -33,10 +32,9 @@ public class AmicableNumber {
|
||||
* @return
|
||||
*/
|
||||
static void findAllInRange(int startValue, int stopValue) {
|
||||
|
||||
/* the 2 for loops are to avoid to double check tuple. For example (200,100) and (100,200) is the same calculation
|
||||
* also to avoid is to check the number with it self. a number with itself is always a AmicableNumber
|
||||
* */
|
||||
* also to avoid is to check the number with it self. a number with itself is always a AmicableNumber
|
||||
* */
|
||||
StringBuilder res = new StringBuilder();
|
||||
int countofRes = 0;
|
||||
|
||||
@ -44,19 +42,22 @@ public class AmicableNumber {
|
||||
for (int j = i + 1; j <= stopValue; j++) {
|
||||
if (isAmicableNumber(i, j)) {
|
||||
countofRes++;
|
||||
res.append("" + countofRes + ": = ( " + i + "," + j + ")" + "\t");
|
||||
res.append(
|
||||
"" + countofRes + ": = ( " + i + "," + j + ")" + "\t"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
res.insert(
|
||||
0,
|
||||
"Int Range of "
|
||||
+ startValue
|
||||
+ " till "
|
||||
+ stopValue
|
||||
+ " there are "
|
||||
+ countofRes
|
||||
+ " Amicable_numbers.These are \n ");
|
||||
0,
|
||||
"Int Range of " +
|
||||
startValue +
|
||||
" till " +
|
||||
stopValue +
|
||||
" there are " +
|
||||
countofRes +
|
||||
" Amicable_numbers.These are \n "
|
||||
);
|
||||
System.out.println(res.toString());
|
||||
}
|
||||
|
||||
@ -68,9 +69,12 @@ public class AmicableNumber {
|
||||
* otherwise false
|
||||
*/
|
||||
static boolean isAmicableNumber(int numberOne, int numberTwo) {
|
||||
|
||||
return ((recursiveCalcOfDividerSum(numberOne, numberOne) == numberTwo
|
||||
&& numberOne == recursiveCalcOfDividerSum(numberTwo, numberTwo)));
|
||||
return (
|
||||
(
|
||||
recursiveCalcOfDividerSum(numberOne, numberOne) == numberTwo &&
|
||||
numberOne == recursiveCalcOfDividerSum(numberTwo, numberTwo)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +85,6 @@ public class AmicableNumber {
|
||||
* @return sum of all the dividers
|
||||
*/
|
||||
static int recursiveCalcOfDividerSum(int number, int div) {
|
||||
|
||||
if (div == 1) {
|
||||
return 0;
|
||||
} else if (number % --div == 0) {
|
||||
|
Reference in New Issue
Block a user