public boolean sum28(int[] nums) { int [] sum28 = {10,2,2,2,2,50}; int sum; for (int i=0; i<sum28.length; i++) //This will cycle through the elements { if (sum28[i] == 2) //If the value contained in sum28[28] is a 2 it will add that to the sum { sum = sum + 2; //This adds a 2 to the sum IF the element has a 2 } else sum = sum + 0; //it it does not have a 2 it adds 0 to make sure only the two's are added. if (sum == 8) //If sum = 8 than it will return true if not it will return false { return true; } else { return false; } } }
Help please. When I complie this code it is telling me it isn't returning a boolean value even though I am telling it to return a true/false. please explain why I can't get it to compile.
--- Update ---
My error is this:Error: public boolean sum28(int[] nums) {
^^^^^^^^^^^^^^^^^
This method must return a result of type boolean
Possible problem: the if-statement structure may theoretically
allow a run to reach the end of the method without calling return.
Consider using a final else {... to ensure that return is always called.