Java Reference
In-Depth Information
Sections 5.2-5.7
*5.1
( Count positive and negative numbers and compute the average of numbers ) Write
a program that reads an unspecified number of integers, determines how many
positive and negative values have been read, and computes the total and average of
the input values (not counting zeros). Your program ends with the input 0 . Display
the average as a floating-point number. Here is a sample run:
Enter an integer, the input ends if it is 0: 1 2 -1 3 0
The number of positives is 3
The number of negatives is 1
The total is 5.0
The average is 1.25
Enter an integer, the input ends if it is 0: 0
No numbers are entered except 0
5.2
( Repeat additions ) ListingĀ 5.4, SubtractionQuizLoop.java, generates five random
subtraction questions. Revise the program to generate ten random addition ques-
tions for two integers between 1 and 15 . Display the correct count and test time.
5.3
( Conversion from kilograms to pounds ) Write a program that displays the follow-
ing table (note that 1 kilogram is 2.2 pounds):
Kilograms Pounds
1 2.2
3 6.6
...
197 433.4
199 437.8
5.4
( Conversion from miles to kilometers ) Write a program that displays the follow-
ing table (note that 1 mile is 1.609 kilometers):
Miles Kilometers
1 1.609
2 3.218
...
9 14.481
10 16.090
5.5
( Conversion from kilograms to pounds and pounds to kilograms ) Write a program
that displays the following two tables side by side:
Kilograms Pounds | Pounds Kilograms
1 2.2 | 20 9.09
3 6.6 | 25 11.36
...
197 433.4 | 510 231.82
199 437.8 | 515 234.09
5.6
( Conversion from miles to kilometers ) Write a program that displays the follow-
ing two tables side by side:
 
Search WWH ::




Custom Search