aspose file tools*
The moose likes Beginning Java and the fly likes simple doubt - Java logic using false and true Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "simple doubt - Java logic using false and true" Watch "simple doubt - Java logic using false and true" New topic
Author

simple doubt - Java logic using false and true

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
hi,

why did that print false?



and that true?

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

and that true?

Are you sure ??


[My Blog]
All roads lead to JavaRanch
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3645
    
  15
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.

Joanne
Virendrasinh Gohil
Ranch Hand

Joined: Jun 09, 2004
Posts: 46
I tried. It printed false both the time.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

André Asantos wrote:why did that print false?

Because it's false.
and that true?

It didn't.
Vishal Kashyap
Ranch Hand

Joined: Aug 07, 2010
Posts: 73

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.


MCSA 2003 | Preparing For OCPJP/SCJP6
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

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.


OCPJP 6
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: simple doubt - Java logic using false and true