java - Finding a return value while passing n variables in a method -
int add3(int...numbers) { for(int number : numbers) { int number1=0; number1= number+number1; } return number1; }
this have written find out summation of n numbers while being passed through method. getting error while getting return value i.e. number1 variable cannot resolved variable type.
you have declare number1 before loop. if define inside loop, not recognized after loop, in return statement.
int add3(int...numbers) { int number1=0; for(int number : numbers) { number1= number+number1; } return number1; }
another suggestion change number1
meaningful name, such sum
.
Comments
Post a Comment