|
The value "0" in this program is the sentinel value. Could any other value be used? A good answer might be:No. You might decide that a special value like "9999" would be a good sentinel, but then what happens if this number happens to occur in the list to be added up? | |
Improving the PromptWith the value "0" as the sentinel, if that value occurs in the list to be added, it can be skipped without any problem (since skipping it affects the sum the same way as adding it in.) Here is the interesting part of the program again, with some additions to make the user prompt more "user friendly:"
Additional statements could correct the dubious grammar for the first few integers, but let's not do that now.C:\users\default\JavaLessons\chap18>java addUpNumbers Symantec Java! JustInTime Compiler Version 210.063 for JDK 1.1.3 Copyright (C) 1996-97 Symantec Corporation Enter first integer (enter 0 to quit): 12 Enter the 2th integer (enter 0 to quit): -3 Enter the 3th integer (enter 0 to quit): 4 Enter the 4th integer (enter 0 to quit): -10 Enter the 5th integer (enter 0 to quit): 0 Sum of the 4 integers: 3 | |
QUESTION 5:Fill in the blank so that the program matches the suggested output. Click Here after you have answered the question |