• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

boolean confusion

 
Susie Chow
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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: }
 
Junilu Lacar
Bartender
Posts: 7607
54
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
sona gold
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
OH MY GOD! I was totally blind. Thank you very much.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic