Java Reference
In-Depth Information
Enter a degree in Celsius:
43 Celsius is 109.4 Fahrenheit
43
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 *
volume = area * length
p
Here is a sample run:
Enter the radius and length of a cylinder:
The area is 95.0331
The volume is 1140.4
5.5 12
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:
16.5
Enter a value for feet:
16.5 feet is 5.0325 meters
2.4
(
Convert pounds into kilograms
) Write a program that converts pounds into kilo-
grams. The program prompts the user to enter a number in pounds, converts it to
kilograms, and displays the result. One pound is
0.454
kilograms. Here is a
sample run:
Enter a number in pounds:
55.5 pounds is 25.197 kilograms
55.5
*2.5
(
Financial application: calculate tips
) Write a program that reads the subtotal and
the gratuity rate, then computes the gratuity and total. For example, if the user
enters
10
for subtotal and
15%
for gratuity rate, the program displays
$1.5
as gra-
tuity and
$11.5
as total. Here is a sample run:
Enter the subtotal and a gratuity rate:
The gratuity is $1.5 and total is $11.5
10 15
**2.6
(
Sum the digits in an integer
) Write a program that reads an integer between
0
and
1000
and adds all the digits in the integer. For example, if an integer is
932
, the
sum of all its digits is
14
.
Hint
: Use the
%
operator to extract digits, and use the
/
operator to remove the
extracted digit. For instance,
932 % 10 = 2
and
932 / 10 = 93
.
Here is a sample run:
Enter a number between 0 and 1000:
The sum of the digits is 27
999