you can pass value to be sum as an array or var args.
public int add(int... nums) {
int sum = 0;
for (int num : nums) {
sum = sum + num;
}
return sum;
}
solved How to add multiple numbers using a method in java? [closed]