February 2017
Beginner
1056 pages
28h 57m
English
And in such indexes, although small pricks
To their subsequent volumes, there is seen
The baby figure of the giant mass
Of things to come.
—WILLIAM SHAKESPEARE, Troilus and Cressida
Suppose you want to compute the average temperature for the seven days in a week. You might use the following code:
Scanner keyboard = new Scanner(System.in);
System.out.println(“Enter 7 temperatures:”);
double sum = 0;
for (int count = 0; count < 7; count++)
{
double next = keyboard.nextDouble();
sum = sum + next;
}
double average = sum / 7;
This works fine if all you want to know is the average. But let’s say you also want to know which temperatures are above and which are below the average. Now you have a problem. In order to compute the average, ...
Read now
Unlock full access