0

Can't display my variable's content

/*I believe the above below should return the value of 11, but instead, I get this: "java: cannot find symbol symbol: variable summ location: class Calculator" Pls, what's the problem?*/ public class Calculator { //creating a method to add integers public Integer adder (int first, int second){ int summ = first+second;//declaring the variable to hold the sum return summ; } //creating the main method public static void main(String[] args) { //creating an object of the calculator class Calculator to_add = new Calculator(); //using the method created earlier to add 9 and 2 together to_add.adder(9,2); //trying to display the sum of 9 and 2 System.out.println("The sum is" + summ); } }

26th Jan 2022, 10:11 AM
Ayomisesebere
Ayomisesebere - avatar
2 Respuestas
+ 4
You call adder() method without assigning the return value into any variable. Create an `Integer` variable named <summ> in main() method to receive the value returned by adder() method. Integer summ = to_add.adder( 9, 2 );
26th Jan 2022, 10:33 AM
Ipang
0
Thx
28th Jan 2022, 9:03 PM
Ayomisesebere
Ayomisesebere - avatar