From 4a6c2df5ac2951212a19800658b8edbb492536b3 Mon Sep 17 00:00:00 2001 From: Tim L Date: Mon, 8 Jul 2024 10:38:31 -0400 Subject: [PATCH] finished Integer utils --- .../assessment1/part1/IntegerUtils.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java index eccbb6c..025a12d 100644 --- a/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java +++ b/src/main/java/com/zipcodewilmington/assessment1/part1/IntegerUtils.java @@ -11,7 +11,9 @@ 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; } /** @@ -19,7 +21,11 @@ public static Integer getSumOfN(Integer n) { * @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; } /** @@ -27,6 +33,8 @@ public static Integer getProductOfN(Integer n) { * @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; } }