Suppose you enter the following condition with x equal to 5

Suppose you enter the following condition with x equal to 5, does the conditions below evaluate to true or false? Why?

a) if(x <= 0 || x = 1)

b) if(x%2 != 2)

Solution

Question a:

a) if(x <= 0 || x = 1) -- Answer: True

if x = 5 then it will return true

5 <= 0 || x = 1 means false || true = true

in if condition any variable value that is greater than 0 it will return true if it is 0 then if condition will return false.

in out case we are assigning 1 value to x so x value is 1. Since we used OR operator it will return true.

b) if(x%2 != 2) -- Answer: true

if we pass x value as 5 then x % 2 = 1 so it is 1 != 2 will return true.

Suppose you enter the following condition with x equal to 5, does the conditions below evaluate to true or false? Why? a) if(x <= 0 || x = 1) b) if(x%2 != 2)

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site