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);

Respuesta :

Answer:

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.