• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Sybex OCA OCP Practice Tests Exam Practice Test Book Chapter 3 wrong answer for 20th question!  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am preparing OCA 1z0-808 exam with Sybex.OCA.OCP.Practice.Tests.Exam book. I encountered wrong answer, because I tested in IDE. 20th question in Chapter 3;

What is the output of the following application?

public class Dancing{
   public static void main(String[] args) {
       int leaders = 10 * (2 + (1 + 2 / 5));
       int followers = leaders * 2;
       System.out.println(leaders + followers < 10 ? "Too few" : "Too many");
   }
}


The answer should be "Too many". But it claimed that it should be "The code does not compile"

I want to infrom about it

Best regards

Onur
 
Ranch Hand
Posts: 69
Eclipse IDE IntelliJ IDE VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Onur,
There should be an address in the front of the book where you can report mistakes. I'd go ahead and report it, because it does compile.

Doug
 
Saloon Keeper
Posts: 2153
278
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find the errata here: https://www.selikoff.net/java-oca-8-programmer-i-study-guide/
 
Onur Tokat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much guys
 
Marshal
Posts: 61766
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Which page was that code on? Are you sure you have copied it exactly? The code you posted does indeed print, “Too many,” but you might have corrected a compiler error when you copied it. There is no mention of such an error in the errata link Ron posted.
Duplicating this discussion in our exam forum.
 
Onur Tokat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Question page is 71, and its answer is 466

I copied from book below;

Question:

20. What is the output of the following application?
package recreation;
public class Dancing {
public static void main(String[] vars) {
int leaders = 10 * (2 + (1 + 2 / 5);
int followers = leaders * 2;
System.out.print(leaders + followers < 10 ? "Too few" : "Too many");
}
}
A. Too few
B. Too many
C. The code does not compile.
D. The code compiles but throws a division by zero error at runtime.

Answer:
20. C. While the code involves numerous operations, none of that matters for solving this
problem. The key to solving it is to notice that the line that assigns the leaders
variable has an uneven number of parentheses. Without balanced parentheses, the
code will not compile, making Option C the correct answer.
 
Campbell Ritchie
Marshal
Posts: 61766
193
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you compare what you have just posted with what you posted originally, you will see that there is one ) after the 5, but that should read )). The answer given in the book that the code fails to compile is therefore correct.
 
Onur Tokat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I missed out, you are right.

When I copied the answer, I realized. Sorry!

I am welcome to coderanch
 
Campbell Ritchie
Marshal
Posts: 61766
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Onur Tokat wrote:. . . When I copied the answer, I realized. Sorry! . . .

Nothing to be sorry about. It goes to show you what a tiny change in the code can do.
 
author & internet detective
Posts: 38917
686
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Douglas Knapp wrote:Onur,
There should be an address in the front of the book where you can report mistakes. I'd go ahead and report it, because it does compile.

Doug


For what it's worth, the book encourages people to post errata in the forums here at CodeRanch. The reason for that is discussion is often warranted (like this example).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!