• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

boolean confusion

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder what is going on on line 9? thanks.
1: public class Q10
2: {
3: public static void main(String[] args)
4: {
5: int i = 10;
6: int j = 10;
7: boolean b = false;
8:
9: if( b = i == j)
10: System.out.println("True");
11: else
12: System.out.println("False");
13: }
14: }
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, the expression i == j is evaluated, giving the boolean value true. This value is then assigned to the boolean variable b. The if statement is then executed.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1: public class Q10
2: {
3: public static void main(String[] args)
4: {
5: int i = 10;
6: int j = 10;
7: boolean b = false;
8:
9: if( b = i == j) // (b = (i == j)
// (b = ( true )
// if ( b = true)

10: System.out.println("True");
11: else
12: System.out.println("False");
13: }
14: }
output
True
 
Susie Chow
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OH MY GOD! I was totally blind. Thank you very much.
 
Space pants. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic