🔒 Closed Logical operators

Status
Not open for further replies.

Aircon

Forum Guru
pahelp naman po

!x && x >= 3
value ng x = 7 true or false?

paki explain naman po and how siya icode using java
 
Solution
Java:
int x = 7;
boolean result = !x && x >= 3;
System.out.println(result);

The E×ρréššion "!x" evaluates to false because the logical NOT operator inverts the truth value of the E×ρréššion "x" (which is true since x = 7 is a non-zero integer). The E×ρréššion "x >= 3" evaluates to true since 7 is greater than or equal to 3. Therefore, the overall E×ρréššion "!x && x >= 3" evaluates to false && true, which results in a final value of false.

So the output of the above code would be "false", indicating that the E×ρréššion "!x && x >= 3" is false when x = 7.
Java:
int x = 7;
boolean result = !x && x >= 3;
System.out.println(result);

The E×ρréššion "!x" evaluates to false because the logical NOT operator inverts the truth value of the E×ρréššion "x" (which is true since x = 7 is a non-zero integer). The E×ρréššion "x >= 3" evaluates to true since 7 is greater than or equal to 3. Therefore, the overall E×ρréššion "!x && x >= 3" evaluates to false && true, which results in a final value of false.

So the output of the above code would be "false", indicating that the E×ρréššion "!x && x >= 3" is false when x = 7.
 
Solution
Java:
int x = 7;
boolean result = !x && x >= 3;
System.out.println(result);

The E×ρréššion "!x" evaluates to false because the logical NOT operator inverts the truth value of the E×ρréššion "x" (which is true since x = 7 is a non-zero integer). The E×ρréššion "x >= 3" evaluates to true since 7 is greater than or equal to 3. Therefore, the overall E×ρréššion "!x && x >= 3" evaluates to false && true, which results in a final value of false.

So the output of the above code would be "false", indicating that the E×ρréššion "!x && x >= 3" is false when x = 7.
nasa basic palang kasi kami paps pano siya icocode kapag ganitong lang
1677330945915.webp

diko kasi siya macode ng tama pero alam kona yung sagot diko lang mapalabas

nasa basic palang kasi kami paps pano siya icocode kapag ganitong lang
Java:
int x = 7;
[/QUOTE]
[QUOTE="CR1T CARUZ, post: 25394135, member: 1470322"]
boolean result = !x && x >= 3;
System.out.println(result);

The E×ρréššion "!x" evaluates to false because the logical NOT operator inverts the truth value of the E×ρréššion "x" (which is true since x = 7 is a non-zero integer). The E×ρréššion "x >= 3" evaluates to true since 7 is greater than or equal to 3. Therefore, the overall E×ρréššion "!x && x >= 3" evaluates to false && true, which results in a final value of false.

So the output of the above code would be "false", indicating that the E×ρréššion "!x && x >= 3" is false when x = 7.
nageerror kasi sa compiler na gamit ko
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 6
    Replies
  • 652
    Views
  • 3
    Participants
Last reply from:
VoidHunter

Online now

Members online
670
Guests online
7,306
Total visitors
7,976

Forum statistics

Threads
2,339,125
Posts
29,307,880
Members
1,122,849
Latest member
John Adrian Quimque
Back
Top