How to create a method takes any number of parameters you give to it ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to create a method takes any number of parameters you give to it ?

it's easy if you want to create a method for example sum the numbers you gave it of integers just type like that int addMethod(int...a){ int sum=0; for(int i : a) sum += i; return sum; } i hope you understand :)

24th Nov 2016, 2:25 AM
Mohammed Fakham
Mohammed Fakham - avatar
2 Answers
0
public int sum(int... s) { int sum=0; for(int i:s){ sum=i+sum; } return sum; }
24th Nov 2016, 4:42 AM
bayram akdemir
bayram akdemir - avatar
0
right 👍
24th Nov 2016, 12:59 PM
Mohammed Fakham
Mohammed Fakham - avatar