Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

simple doubt - Java logic using false and true

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

why did that print false?



and that true?

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and that true?

Are you sure ??
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Th only difference between those two is that we can't see how you declare x and y in the second one, although I can't imagine any declaration that would cause it to print true.
Why don't you show us how you are declaring x and y and how you are calling these two pieces of code.
 
Virendrasinh Gohil
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried. It printed false both the time.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
André Asantos wrote:why did that print false?

Because it's false.
and that true?

It didn't.
 
Vishal Kashyap
Ranch Hand
Posts: 73
BSD C++ Fedora
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
André Asantos wrote:hi,

why did that print false?



and that true?



Because, the truth table of two variable x and y will be true if and only if both values are true. that's why your first code prints false.

but, as we can see; you have not clearly shown declaration statement. So, we could not understand you here.
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishal Kashyap wrote:...but, as we can see; you have not clearly shown declaration statement...

Anyway does the declaration statement really matter? (x && y) immediately follows clear boolean assignments to x and y. 'false' can be expected only when there is something else between the assignment and the expression.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point is we don't *know* what's there--the two chunks could be completely unrelated and in different files, or there might be no separation between the two chunks at all. Since the claim that the behavior of boolean "and" is broken, there's obviously more information needed, because it's extremely unlikely "and" is broken.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic