Java Reference
In-Depth Information
x n +1 = x 2 (3
ax n . Write the corresponding program. Does it converge
faster or slower than Newton's method for f ( x )= a
x 2 ?
Exercise 2.6 (Variable scope)
Consider the following program:
class ScopeExercise
{ public static void main( String [ ]
a)
int j=5;
for ( int i=0;i < 10; i++)
System . out . println ( "i=" +i ) ;
j+=i +10;
System . out . println ( "j=" +j ) ;
}
}
Explain what is wrong with this program. How do we change the scope
of variable i in order to compile?
Exercise 2.7 (Chevalier DeMere and the birth of probability **)
In the 17th century, gambler Chevalier De Mere asked the following
question of Blaire Pascal and Pierre de Fermat: How can one compare
the following probabilities
- Getting at least one ace in four rolls of a dice,
- Getting at least one double ace using twenty-four rolls of two dices.
Chevalier De Mere thought that the second chance game was better but
lost constantly. Using the function Math.random() and loop statements,
experiment with the chance of winning for each game. After running
many trials (say, a million of them), observe that the empirical probabil-
ity of winning with the first game is higher. Prove that the probability of
winning for the first and second games are respectively 6 4 and 3 36 24 .
Exercise 2.8 (Saint Petersburg paradox **)
The following game of chance was introduced by Nicolas Bernoulli: A
gamer pays a fixed fee to play, and then a fair coin is tossed repeatedly
until, say, a tail first appears. This ends the game. The pot starts at 1
euro and is doubled every time a head appears. The gamer wins whatever
is in the pot after the game ends. Show that you win 2 k− 1 euros if the
coin is tossed k times until the first tail appears. The paradox is that
whatever the initial fee, it is worth playing this game. Indeed, prove that
the expected gain is k =1
= k =1
1
1
2
2 k 2 k− 1
=
. Write a program
 
 
Search WWH ::




Custom Search