Armynavy123
New Member
- Joined
- Aug 31, 2011
- Messages
- 1
- Reaction score
- 0
- Points
- 1
I am doing coding bat program practice and I have a question that I don't get why I am wrong. The question is...
Given two int values, return their sum. Unless the two values are the same, then return double their sum.
My code is
public int sumDouble(int a, int b) {
if (a == b) {
return(a + b * 2);
}
return(a+b);
}
Every two numbers worked except for when (2, 2) was passed in. My program returned 6 when it was supposed to return 8. What the heck happpened?!
Aghhh good call guys, thank you all for the math lesson on order of operations.
Given two int values, return their sum. Unless the two values are the same, then return double their sum.
My code is
public int sumDouble(int a, int b) {
if (a == b) {
return(a + b * 2);
}
return(a+b);
}
Every two numbers worked except for when (2, 2) was passed in. My program returned 6 when it was supposed to return 8. What the heck happpened?!
Aghhh good call guys, thank you all for the math lesson on order of operations.