In this method, what does mean the "...k" ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

In this method, what does mean the "...k" ?

Static int sum ( int ...k){ Int sum = 0; for ( int i:k) sum +=i; Return sum; }

17th Feb 2020, 6:45 PM
Hichem GOUIA
Hichem GOUIA - avatar
2 Answers
+ 2
It is called variable arguments or varargs in short. It behaves like an array and nothing more. See if this helps- https://code.sololearn.com/cd3JmZlxH7NR/?ref=app
17th Feb 2020, 6:57 PM
Avinesh
Avinesh - avatar
+ 4
Hichem GOUIA As Avinesh mentioned it is called varargs. The method accepts arrays but also arguments (which get treated like arrays)
17th Feb 2020, 7:02 PM
Denise Roßberg
Denise Roßberg - avatar