| Author |
can anyone help me with these exam question?
|
fajing ye
Greenhorn
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 = in.next();
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 = in.next();
[6 marks]
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
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 ?
|
Joanne
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16686
|
|
QuoteYourSources
|
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
Greenhorn
Joined: Mar 23, 2009
Posts: 8
|
|
|
[deleted]
|
 |
 |
|
|
subject: can anyone help me with these exam question?
|
|
|