• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Sybex chapter 3 page 107 OCP 11 ProgrammerI

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the practice exercises, in the question 9, the real answer should be 4 5 1, not 4 6 1.. Following the snippet :
               int a = 2, b = 4, c = 2;
System.out.println(a > 2 ? --c : b++);
System.out.println(b = (a != c ? a : b++));
System.out.println((a > b) ? (b < c ? b : 2) : 1);

Answer: 4 5 1
Look, in the second line, b its post-increment, not pre increment to be 6, should be 5, but there are no answer for 5. If was this snippet:
               int a = 2, b = 4, c = 2;
System.out.println(a > 2 ? --c : b++);
System.out.println(b = (a != c ? a : ++b));
System.out.println((a > b) ? (b < c ? b : 2) : 1);

The answer should be: 4 6 1.
But in the book, b its post increment,so the real answer is 4 5 1,but there's no option for this

Correct?
 
Marshal
Posts: 25594
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I compile it and run it, the output is 4 5 1. I leave it to you to explain why that is the case. (The line you're disagreeing with is equivalent to the notorious "b = b++", isn't it?)

By the way, the output from your revised version is 4 6 1.
 
Nicholas Barbosa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nicholas Barbosa wrote:In the practice exercises, in the question 9, the real answer should be 4 5 1, not 4 6 1.. Following the snippet :
               int a = 2, b = 4, c = 2;
System.out.println(a > 2 ? --c : b++);
System.out.println(b = (a != c ? a : b++));
System.out.println((a > b) ? (b < c ? b : 2) : 1);

Answer: 4 5 1
Look, in the second line, b its post-increment, not pre increment to be 6, should be 5, but there are no answer for 5. If was this snippet:
               int a = 2, b = 4, c = 2;
System.out.println(a > 2 ? --c : b++);
System.out.println(b = (a != c ? a : ++b));
System.out.println((a > b) ? (b < c ? b : 2) : 1);

The answer should be: 4 6 1.   But in the book, b its post increment,so the real answer is 4 5 1,but there's no option for this.

Correct?

 
Nicholas Barbosa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:When I compile it and run it, the output is 4 5 1. I leave it to you to explain why that is the case. (The line you're disagreeing with is equivalent to the notorious "b = b++", isn't it?)

By the way, the output from your revised version is 4 6 1.

The true answer is 4 5 1,cause b is post increment and not pre increment,but there s no option for answer 4 5 1 in the book.
 
Paul Clapham
Marshal
Posts: 25594
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, sorry, I got it backwards, didn't I? Yes, it looks like you're correct.
 
Nicholas Barbosa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:Ah, sorry, I got it backwards, didn't I? Yes, it looks like you're correct.

yes!! Oh,ok
I'm 15 years old and I'm studying hard for the exam, you dont know how your answers ,makes me happy !! Thanks!!! I'm in the right way...oh yeeees!!
 
author & internet detective
Posts: 39997
807
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The book says the answer is A/D/E which goes with 1/4/5 (no order specified on thsi queston).

Where do you see the book saying it is 6?
 
Marshal
Posts: 69495
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So with no ordering 145 would count as the same output as 451? Paul and I both got 451. The OP posted a changed version of the code with ++b instead of b++ in line 3, so only that code of OP's produces a 6 anywhere.
 
Jeanne Boyarsky
author & internet detective
Posts: 39997
807
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:So with no ordering 145 would count as the same output as 451?


Correct. The question asks which of the #s appear in the output
 
Nicholas Barbosa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

Campbell Ritchie wrote:So with no ordering 145 would count as the same output as 451?


Correct. The question asks which of the #s appear in the output



Yes, in my book, there is no option for 4 5 1, only for 4 6 1. This is the problem.
 
Campbell Ritchie
Marshal
Posts: 69495
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is different from what Jeanne found. I don't have the book. Please post a scanned/photographed image of that page showing who you got 461.
 
Nicholas Barbosa
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:That is different from what Jeanne found. I don't have the book. Please post a scanned/photographed image of that page showing who you got 461.



Hi,

I used a quiz from Wiley Test Banks and I found the true answer, thanks for attention!
 
It runs on an internal combustion engine. This ad does not:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic