Question

Assume that n is 5 and k is 2. Which of the Boolean expressions are true? 0! (0 <= n && n <= k) n >= 0 && k > 0 05 < n && n <
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the solution, if you have any doubts then you can write in the comment section.

Please give feedback.

Solution: n=5, k=2

(1) !(0<=n && n<=k) true

Here 0<=n is true, n<=k is false And && operator will return true only when both expression results in true, so here both expressions are not true so it results in false and now we have expression !(false), ! alter true to false or false to true, so finally expression result is true.

(2)  (n>=0 && k>0) true

Here n>=0 is true, k>0 is true And && operator will return true only when both expression results in true, so here both expressions are true so it results in true.

(3) (5<n && n<k || k<10) true

Here 5<n is false, n<k is false k<10 is true.

and (&&) operator will return true only when both expressions results in true.

or( || )operator will return true if at least 1 argument is true.

So here 1 argument is true so it results in true.

(4) (0<=n || n<k) true

Here 0<=n is true, n<k is false.

or( || )operator will return true if atleast 1 argument is true.

So here 1 argument is true so it results in true.

(5) !(n<=5) false

Here n<=5 is true and !(n<=5) becomes !(true) so it results in false.

(6) (0<=k<n) (It depends on language) in c++ it results true, in java it results compile-time error.

According to java :

It is not a valid Boolean expression, it results in a compile-time error. because 0<=k will result in true and now (true<n) which is not a valid comparison.

According to c++ :

It is a valid Boolean expression because 0<=k will result in 1 and now (1<n) returns 1 which means true.

Basically we can say this is an invalid Boolean Expression because Boolean Expression compares as long as the type of 2 operands is the same, but as 1st comparison results in true and now operands true and n, so incompatible type, so it results in an error.

Thank You!

Add a comment
Know the answer?
Add Answer to:
Assume that n is 5 and k is 2. Which of the Boolean expressions are true?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT