1. Write an if-­statement that increases the variable num1 by one and reduces the variable num2 by 1, if the variables are not equal.

MY ANSWER:
int num1 = 11;
int num2 = 10;
int counter = 1;

If (num1 != num2)
{
Num2+ counter
}

If (num2 != num1)
{
Num1 - counter
}

IS IT CORRECT? can someone help.
Thanks

1 answer

why two checks? If they are not equal, do both changes.
The way you have it, changing Num2 might make them equal, and the 2nd check will fail. In fact, the way you have initialized the variables, the 2nd check will definitely fail!
Similar Questions
  1. public class Methods {public Methods() { } public int north(int num1, int num2) { int temp = num1; num1 = num2; num2 = temp;
    1. answers icon 1 answer
  2. Which situation demonstrates causation?(1 point)Responses A change in one variable produces a change in the other. A change in
    1. answers icon 1 answer
    1. answers icon 2 answers
  3. What variable is typically graphed on the y-axis?(1 point)Responses the constant variable the composite variable the independent
    1. answers icon 1 answer
more similar questions