Skip to content

Commit

Permalink
finished Integer utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim L authored and Tim L committed Jul 8, 2024
1 parent c535ff2 commit 4a6c2df
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@ public class IntegerUtils {
* @return the sum of all integers between 0 and not including `n`
*/
public static Integer getSumOfN(Integer n) {
return null;
int sum = n * (n + 1)/2;
return sum;
// return null;
}

/**
* @param n integer value input by client
* @return the product of all integers between 0 and not including `n`
*/
public static Integer getProductOfN(Integer n) {
return null;
int result = 1;
for (int i = 2; i <= n; i++)
result = result * i;
return result;
// return null;
}

/**
* @param val integer value input by client
* @return integer with identical digits in the reverse order
*/
public static Integer reverseDigits(Integer val) {
return null;
String reverse = new StringBuilder(String.valueOf(val)).reverse().toString();
return Integer.parseInt(reverse);
// return null;
}
}

0 comments on commit 4a6c2df

Please sign in to comment.