Java Reference
In-Depth Information
Sections 4.2-4.7
*4.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:
1 2 -1 3 0
Enter an integer, the input ends if it is 0:
The number of positives is 3
The number of negatives is 1
The total is 5
The average is 1.25
Enter an integer, the input ends if it is 0:
No numbers are entered except 0
0
4.2
( Repeat additions ) Listing 4.4, SubtractionQuizLoop.java, generates five ran-
dom subtraction questions. Revise the program to generate ten random addition
questions for two integers between 1 and 15 . Display the correct count and test
time.
4.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
4.4
( Conversion from miles to kilometers ) Write a program that displays the following
table (note that 1 mile is 1.609 kilometers):
Miles Kilometers
1 1.609
2 3.218
...
9 14.481
10 16.090
4.5
( Conversion from kilograms to pounds and pounds to kilograms ) Write a program
that displays the following two tables side by side (note that 1 kilogram is 2.2
pounds and that 1 pound is .453 kilograms):
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
Search WWH ::




Custom Search