File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
SCJP 1.6 Study Guide: Ch4 Q9
Db Riekhof
Greenhorn
Joined: May 21, 2009
Posts: 10
posted
Sep 27, 2012 11:13:44
0
I'm getting different results when I run this on my 1.6 JVM than what the book says.
It's a question about short circuit operators. Reducing it to the bare minimum:
int a = 0; int b = 0; if ( true || ++a > 5 | b++ > 5 ) System.out.println( "foo"); System.out.println( "a=" + a + ", b=" + b );
The book says b should equal 1.
My JVM says it equals 0.
So which is it? Should b be incremented to 1 according to official Java?
Db Riekhof
Greenhorn
Joined: May 21, 2009
Posts: 10
posted
Sep 27, 2012 11:18:02
0
Doh, I see my problem. I missed a set of parens. It should be this:
if ( (true || ++a > 5) | b++ > 5 ) System.out.println( "foo");
Now it makes sense.
Rameshwar Soni
Ranch Hand
Joined: Feb 03, 2011
Posts: 246
posted
Sep 27, 2012 11:21:23
0
1)Yes i executed your code for a quick answer and it gives me 0 too.
2) Could you tell me the page number of the book from where you have posted the question.
3) It might also be an printing mistake in book so please check the errata and also check whether you have copied your code properly from book
Rameshwar Soni
Ranch Hand
Joined: Feb 03, 2011
Posts: 246
posted
Sep 27, 2012 11:24:36
0
Db Riekhof wrote:
Doh, I see my problem. I missed a set of parens.
Ohh!!! It happens
<edit> Sorry i didn't read it properly that you had already told that it is Chp 4 Q9.
I agree. Here's the link:
http://zeroturnaround.com/jrebel
subject: SCJP 1.6 Study Guide: Ch4 Q9
Similar Threads
Substring
Brackets problem
Basic Questions on Data Types
Array assignment
Question on hashCode implementation
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter