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

6th Jan 2020, 9:37 PM
Vitaliy Reshetar
Vitaliy Reshetar - avatar
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 :-)
6th Jan 2020, 9:51 PM
PapaBT
PapaBT - avatar
+ 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
7th Jan 2020, 1:16 AM
Avinesh
Avinesh - avatar
+ 1
Avinesh Thank you!
7th Jan 2020, 8:17 AM
Vitaliy Reshetar
Vitaliy Reshetar - avatar
0
PapaBT , ohh that seems an extremely useful function! Thank you very much
6th Jan 2020, 9:58 PM
Vitaliy Reshetar
Vitaliy Reshetar - avatar