• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
IntelliJ IDE Eclipse IDE VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 3654
516
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much guys
 
Marshal
Posts: 74034
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 74034
332
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 74034
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 40747
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
grapes are vegan food pellets. Eat this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic