Ask Question

Analyze the following code (in both cases number has been declared and initialized) : Code 1: boolean even; if (number % 2 = = 0) even = true; else even = false; Code 2: boolean even = (number % 2 = = 0);

+3
Answers (1)
  1. 8 February, 04:03
    0
    Both codes are correct. The value of even is true when the number is even.

    Explanation:

    Code 1:

    number %2 = =0 means that when dividing number by 2 is the remainder coming out is zero. If it is true then even becomes is true if it is false then else statement is executes in which even becomes false. Means the number is odd. This code is simple and easy to understand.

    Code 2:-

    This code is a bit tricky and takes time to understand. even becomes true

    when the number is divisible by 0 and false when it is not.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Analyze the following code (in both cases number has been declared and initialized) : Code 1: boolean even; if (number % 2 = = 0) even = ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers