This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

simple doubt - Java logic using false and true

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

why did that print false?



and that true?

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

and that true?


Are you sure ??
 
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.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried. It printed false both the time.
 
Author
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.
 
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.
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • 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
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.
 
I wasn't selected to go to mars. This tiny ad got in ahead of me:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic