Booleans in Java -


i beginner , started learn java language. encountered problem in book booleans. don't know how find value of questions , wondering if can give me sample of how code supposed like. appreciated.

question in book:

suppose value of b false , value of x 0. value of each of following expressions

a) b && x == 0

b) b || x == 0

c) !b && x == 0

d) !b || x == 0

e) b && x != 0

f) b || x != 0

g) !b && x != 0

h) !b || x != 0

i don't know how execute problem, help!

here how approach problem:

  • recall && , || need boolean on both sides
  • recall ! inverts value of boolean
  • recall binary operations != , == convert pairs of ints booleans
  • start right side; decide if it's true or false
  • put result line above in expression
  • compute result using truth table corresponding logical operator.

let's use first couple of exercises examples:

b && x == 0

you know b false, result of and known right away: it's false - there's no need else.

b || x == 0

  1. you know b false, result of or not known right away.
  2. compute x == 0 (the value true)
  3. compute b || true (the value true, because or-ing true true).

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -