CJCoding With Joseph

Varargs Sum Method

Write a method sum(int... nums) that accepts any number of int arguments and returns their total. Call sum(1, 2, 3, 4) and print the result:

10

Loop over nums with a for-each loop and add each value.

Expected Output:

10
Topics:
Methods
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.