Java Reference
In-Depth Information
Output
S ELF C HECK
5. How would you modify the nested loops so that you print a square
instead of a triangle?
6. What is the value of n after the following nested loops?
int n = 0;
for (int i = 1; i <= 5; i++)
for (int j = 0; j < i; j++)
n = n + j;
246
247
6.4 Processing Sentinel Values
Suppose you want to process a set of values, for example a set of measurements. Your
goal is to analyze the data and display properties of the data set, such as the average
or the maximum value. You prompt the user for the first value, then the second value,
then the third, and so on. When does the input end?
One common method for indicating the end of a data set is a sentinel value, a value
that is not part of the data. Instead, the sentinel value indicates that the data has come
to an end.
Search WWH ::




Custom Search