File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can anyone help me with these exam question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can anyone help me with these exam question?" Watch "can anyone help me with these exam question?" New topic

can anyone help me with these exam question?

fajing ye

Joined: Nov 27, 2011
Posts: 2
hello guys i am a fifty years old man and i am doing IT degree. i am having a exam in next Tuesday, but there are still some question in sample exam paper that i could figure out. hope some one can help me out.

Question 28

i) Define the term "logic error". Provide an example of a logic error and explain how a logic error can be found. [2 marks]

ii) The following segment of code is supposed to validate that a user inputs either ā€œyā€ or ā€œnā€ when prompted to continue the program. The program does not contain any syntax errors. However, when the program is tested, the loop does not terminate. In your answer booklet, state the line(s) in which the error(s) occur(s), copy that (those) line(s) and circle the error(s). Write the correct code for only the line(s) with error(s).

1. System.out.print("Do you wish to continue (y/n)? ");
2. String answer =;
3. System.out.println(answer);
4. while(!answer.equalsIgnoreCase("y") && answer.equalsIgnoreCase("n"));
5. {
6. System.out.print("ERROR! Answer must be either y or n: ");
7. }
8. answer =;
[6 marks]
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
i. Have you tried Google.

ii. Try to explain in English (or your native language) what that code does ? How does it differ from what it is supposed to do ?

Henry Wong

Joined: Sep 28, 2004
Posts: 20525


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Thomas Kennedy
Ranch Hand

Joined: Jan 20, 2008
Posts: 137
The requirement is to check that the user typed a y or n. But the existing loop does not let the user type a new value after typing a bad one. So the existing line 8, which prompts for a new value, needs to be moved back inside the loop.

Costs matter. Justice lies in processes not outcomes. Crime is caused by criminals.
Nolan Lefler

Joined: Mar 23, 2009
Posts: 8
I agree. Here's the link:
subject: can anyone help me with these exam question?
It's not a secret anymore!