0
How to create a method with variable number of arguments?
Variable length arguments
2 Answers
- 1
public int sum(int...nums) {
int sum=0;
for(int x:nums)
sum+=x;
return sum;
}
Now we can pass any number of arguments to this method.
sum(1,2,3)
sum(20,21,23,45)