In programming specifically Java Use specific realworld exam

In programming, specifically Java Use specific, real-world examples to describe the uses of the logical AND operator (&&), the logical OR operator (||), the logical NOT operator (!) and the combination of those operators in making decisions.

Solution

Logical && is used to check for 2 conditions. If 2 conditions hold true, the first block will be executed, and the second block is executed otherwise.

Consider a real time example: You want to read the scores of a student in the range: 0 - 100. Unless otherwise, consider it an invalid score.

So, the condition to be verified should be:

if(score >= 0 && score <= 100)

System.out.println(\"Valid score.\");

else

System.out.println(\"Invalid score.\");

Logical &|| is used to check for 2 conditions. If atleast one condition hold true, the first block will be executed, and the second block is executed otherwise.

Consider a real time example: You want to read the scores of a student in the range: 0 - 100. Unless otherwise, consider it an invalid score. The other way of representing the same condition is:

if(score < 0 || score > 100)

System.out.println(\"Invalid score.\");

else

System.out.println(\"Valid score.\");

Logical ! is used to check for a conditions. This is a unary operator. If the condition holds false, the first block will be executed, and the second block is executed otherwise.

Consider a real time example: You want to check if a value is non-zero.

So, the condition to be verified should be:

if(value != 0)

System.out.println(\"Value is valid.\");

else

System.out.println(\"Value is invalid.\");

In programming, specifically Java Use specific, real-world examples to describe the uses of the logical AND operator (&&), the logical OR operator (||),

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site