Java Reference
In-Depth Information
**5.25
( Compute p ) You can approximate p by using the following series:
1) i + 1
(
-
1
3
1
5
1
7
1
9
1
11
p =
¢
-
+
-
+
-
+ g +
4
1
-
2 i
1
Write a program that displays the p value for i = 10000 , 20000 , …, and
100000 .
**5.26
( Compute e ) You can approximate e using the following series:
1
1!
1
2!
1
3!
1
4!
1
i !
e
=
1
+
+
+
+
+ g +
Write a program that displays the e value for i = 10000 , 20000 , …, and
100000 . ( Hint : Because i !
=
i
*
( i
-
1)
* c *
2
*
1, then
1
i ! is
1
i ( i
-
1)!
Initialize e and item to be 1 and keep adding a new item to e . The new item is
the previous item divided by i for i = 2 , 3 , 4 , ....)
**5.27
( Display leap years ) Write a program that displays all the leap years, ten per line,
from 101 to 2100, separated by exactly one space. Also display the number of
leap years in this period.
**5.28
( Display the first days of each month ) Write a program that prompts the user to
enter the year and first day of the year, and displays the first day of each month
in the year. For example, if the user entered the year 2013 , and 2 for Tuesday,
January 1, 2013, your program should display the following output:
January 1, 2013 is Tuesday
...
December 1, 2013 is Sunday
**5.29
( Display calendars ) Write a program that prompts the user to enter the year and
first day of the year and displays the calendar table for the year on the console. For
example, if the user entered the year 2013 , and 2 for Tuesday, January 1, 2013,
your program should display the calendar for each month in the year, as follows:
January 2013
Sun
Mon
Tue
Wed
Thu
Fri
Sat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
Search WWH ::




Custom Search