0
Can you explain this pease of code?
Encountered this code while playing. What does "sum(int ...k)" in this code mean (line 7)? It seems like it accepts multiple entries. Thank you for your answer in advance! https://code.sololearn.com/cb3A51z2IdWg/?ref=app
4 Answers
+ 1
static int sum(int ...k){
is a functiondeclaration with a vararg. You can call the function with different count of int-Parameters.
Inside the function k is an array.
Hope that helps :-)
+ 2
Just adding to what he mentioned, always remember just in case you have to pass two parameters, one is an integer value and other an integer array then the vararg declaration should always be the last parameter. Eg-
(int a, int...b) // this will work
(int...a, int b) // this will not work
+ 1
Avinesh Thank you!
0
PapaBT , ohh that seems an extremely useful function!
Thank you very much



