CJCoding With Joseph

Sum with Varargs

Write a static method named sum that accepts a variable number of int arguments (varargs) and returns their total. In main, print the results of two calls, each on its own line, exactly:

6
100

The first call is sum(1, 2, 3) (which is 6) and the second is sum(10, 20, 30, 40) (which is 100).

Expected Output:

6
100
Topics:
Miscellaneous
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.