Question: Java programming question 5. Consider the class below. public class Addition { private int sum = 0; public static void add (int x, int sum)

Java programming question

Java programming question 5. Consider the class below. public class Addition {private int sum = 0; public static void add (int x, int

sum) { sum += x; } //end method add public static voidmain(String[] args) { int sum = 0; add (2, sum); add (3,

sum) ; add (4, sum); System.out.println("The total is: " + sum); }//end main method } //end class Addition expected the program's output to

5. Consider the class below. public class Addition { private int sum = 0; public static void add (int x, int sum) { sum += x; } //end method add public static void main(String[] args) { int sum = 0; add (2, sum); add (3, sum) ; add (4, sum); System.out.println("The total is: " + sum); } //end main method } //end class Addition expected the program's output to say: The total is: 9 That is, the programmer wanted the add method to add values to the sum class variable. Fix the code so that it works properly by making edits such as changing names, crossing out code, adding code, etc

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!