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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -