Java Reference
In-Depth Information
**5.34
( Print calendar ) Programming Exercise 3.21 uses Zeller's congruence to calculate
the day of the week. Simplify Listing 5.12, PrintCalendar.java, using Zeller's algo-
rithm to get the start day of the month.
5.35
( Geometry: area of a pentagon ) The area of a pentagon can be computed using the
following formula:
s 2
5
*
Area
=
5
4
*
tan
¢
Write a program that prompts the user to enter the side of a pentagon and displays
the area. Here is a sample run:
Enter the side:
The area of the pentagon is 52.04444136781625
5.5
*5.36
( Geometry: area of a regular polygon ) A regular polygon is an n -sided polygon in
which all sides are of the same length and all angles have the same degree (i.e., the
polygon is both equilateral and equiangular). The formula for computing the area
of a regular polygon is
s 2
n
*
Area
=
¢ n
4
*
tan
Write a method that returns the area of a regular polygon using the following
header:
public static double area( int n, double side)
Write a main method that prompts the user to enter the number of sides and the
side of a regular polygon and displays its area. Here is a sample run:
5
Enter the number of sides:
Enter the side:
The area of the polygon is 72.69017017488385
6.5
5.37
( Format an integer ) Write a method with the following header to format the inte-
ger with the specified width.
public static String format( int number, int width)
The method returns a string for the number with one or more prefix 0 s. The size of
the string is the width. For example, format(34, 4) returns 0034 and
format(34, 5) returns 00034 . If the number is longer than the width, the
method returns the string representation for the number. For example,
format(34, 1) returns 34 .
 
Search WWH ::




Custom Search