John wants to check if a number is even or odd. Which control structure should he use to make the decision?

  • For Loop
  • If-Else Statement
  • Switch Statement
  • While Loop
John should use an If-Else statement to check if a number is even or odd. The If-Else statement evaluates a condition and executes different code blocks based on whether the condition is true or false. In this case, John can use the modulus operator (%) to check if the number divided by 2 leaves a remainder of 0 (even) or not (odd).
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *