Java Reference
In-Depth Information
P ROGRAMMING E XERCISES
Debugging TIP
The compiler usually gives a reason for a syntax error. If you don't know how to correct it,
compare your program closely, character by character, with similar examples in the text.
learn from examples
Pedagogical Note
Instructors may ask you to document your analysis and design for selected exercises. Use
your own words to analyze the problem, including the input, output, and what needs to be
computed, and describe how to solve the problem in pseudocode.
document analysis and design
Sections 2.2-2.12
2.1
( Convert Celsius to Fahrenheit ) Write a program that reads a Celsius degree in
a double value from the console, then converts it to Fahrenheit and displays the
result. The formula for the conversion is as follows:
fahrenheit = (9 / 5) * celsius + 32
Hint : In Java, 9 / 5 is 1 , but 9.0 / 5 is 1.8 .
Here is a sample run:
Enter a degree in Celsius: 43
43 Celsius is 109.4 Fahrenheit
2.2
( Compute the volume of a cylinder ) Write a program that reads in the radius
and length of a cylinder and computes the area and volume using the following
formulas:
area = radius * radius * p
volume = area * length
Here is a sample run:
Enter the radius and length of a cylinder: 5.5 12
The area is 95.0331
The volume is 1140.4
2.3
( Convert feet into meters ) Write a program that reads a number in feet, converts it
to meters, and displays the result. One foot is 0.305 meter. Here is a sample run:
Enter a value for feet: 16.5
16.5 feet is 5.0325 meters
Search WWH ::




Custom Search