Java Reference
In-Depth Information
where s is the length of a side. Here is a sample run:
Enter the side: 5.5
The area of the hexagon is 78.5895
*2.17
( Science: wind-chill temperature ) How cold is it outside? The temperature alone
is not enough to provide the answer. Other factors including wind speed, rela-
tive humidity, and sunshine play important roles in determining coldness outside.
In 2001, the National Weather Service (NWS) implemented the new wind-chill
temperature to measure the coldness using temperature and wind speed. The
formula is
35.75 v 0.16
0.4275 t a v 0.16
t wc =
35.74
+
0.6215 t a
-
+
where t a is the outside temperature measured in degrees Fahrenheit and v is the
speed measured in miles per hour. t wc is the wind-chill temperature. The formula
cannot be used for wind speeds below 2 mph or temperatures below
-
58 ºF or
above 41ºF.
Write a program that prompts the user to enter a temperature between
58 ºF and
41ºF and a wind speed greater than or equal to 2 and displays the wind-chill tem-
perature. Use Math.pow(a, b) to compute v 0.16 . Here is a sample run:
-
Enter the temperature in Fahrenheit between -58°F and 41°F:
5.3
Enter the wind speed (>=2) in miles per hour: 6
The wind chill index is -5.56707
2.18
( Print a table ) Write a program that displays the following table. Cast floating-
point numbers into integers.
a b pow(a, b)
1 2 1
2 3 8
3 4 81
4 5 1024
5 6 15625
*2.19
( Geometry: area of a triangle ) Write a program that prompts the user to enter
three points (x1, y1) , (x2, y2) , (x3, y3) of a triangle and displays its area.
The formula for computing the area of a triangle is
s
=
(side1
+
side2
+
side3)/2;
area
= 2
s ( s
-
side1)( s
-
side2)( s
-
side3)
Here is a sample run:
Enter three points for a triangle: 1.5 -3.4 4.6 5 9.5 -3.4
The area of the triangle is 33.6
 
Search WWH ::




Custom Search