• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can anyone help me with these exam question?

 
fajing ye
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Marshal
Pie
Posts: 21518
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Nolan Lefler
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[deleted]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic