This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes boolean confusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "boolean confusion" Watch "boolean confusion" New topic
Author

boolean confusion

Susie Chow
Ranch Hand

Joined: Jun 12, 2001
Posts: 33
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

Joined: Feb 26, 2001
Posts: 4442
    
    5

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.

Junilu - [How to Ask Questions] [How to Answer Questions]
sona gold
Ranch Hand

Joined: Feb 14, 2001
Posts: 234

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

sona<br />SCJP
Susie Chow
Ranch Hand

Joined: Jun 12, 2001
Posts: 33
OH MY GOD! I was totally blind. Thank you very much.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: boolean confusion
 
Similar Threads
Presidence in an IF statement
operators
precedence
Question by Sreenivasa Kumar Majji
Majji Mock Exam # 1