Exercise: Digit Sum Redux

Write a console program with the following methods:

Your program, without methods, can look like this:

int[] randNrs = createRandomArray(10, 0, 200);
int[] digitSums = new int[randNrs.Length];
for (int i = 0; i < digitSums.length; i++)
{
    int digitSum = getDigitSum(randNrs[i]);
    digitSums[i] = digitSum;
}

System.out.println("Random numbers: ");
System.out.println(toString(randNrs));
System.out.println("Digit sums: ");
System.out.println(toString(digitSums));
Example program output:
Random numbers:
158, 124, 179, 44, 86, 189, 121, 168, 194, 106
Digit sums:
14, 7, 17, 8, 14, 18, 4, 15, 14, 7

Hand in instructions

  1. Make sure your program runs correctly.
  2. Hand in your program by uploading Main.java to Moodle.