You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: thinkjava.tex
+18-18Lines changed: 18 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1923,7 +1923,7 @@ \section{Exercises}
1923
1923
Thursday 16 July 2015
1924
1924
\end{stdout}
1925
1925
1926
-
%{\em Hint:} You should be able to copy, paste, and modify the code from Step 4 when completing Step 5.
1926
+
%{\it Hint:} You should be able to copy, paste, and modify the code from Step 4 when completing Step 5.
1927
1927
\end{enumerate}
1928
1928
1929
1929
\end{exercise}
@@ -1954,7 +1954,7 @@ \section{Exercises}
1954
1954
1955
1955
\end{enumerate}
1956
1956
1957
-
{\em Hint:} You might want to use additional variables to hold values during the computation.
1957
+
{\it Hint:} You might want to use additional variables to hold values during the computation.
1958
1958
Variables that are used in a computation but never displayed are sometimes called ``intermediate'' or ``temporary'' variables.
1959
1959
1960
1960
\end{exercise}
@@ -2625,7 +2625,7 @@ \section{Exercises}
2625
2625
It should (1) prompt the user for input, (2) read an integer from the keyboard, (3) calculate the result, and (4) use \java{printf} to display the output.
2626
2626
For example, {\tt"5000 seconds = 1 hours, 23 minutes, and 20 seconds"}.
2627
2627
2628
-
{\em Hint:} Use the modulus operator.
2628
+
{\it Hint:} Use the modulus operator.
2629
2629
\end{exercise}
2630
2630
2631
2631
@@ -3420,7 +3420,7 @@ \section{Exercises}
3420
3420
\item What is the output of the following program?
3421
3421
Be precise about where there are spaces and where there are newlines.
3422
3422
3423
-
{\em Hint:} Start by describing in words what \java{ping} and \java{baffle} do when they are invoked.
3423
+
{\it Hint:} Start by describing in words what \java{ping} and \java{baffle} do when they are invoked.
3424
3424
3425
3425
\item Draw a stack diagram that shows the state of the program the first time \java{ping} is invoked.
3426
3426
@@ -4155,7 +4155,7 @@ \section{Exercises}
4155
4155
4156
4156
\begin{enumerate}
4157
4157
4158
-
\item Draw a stack diagram that shows the state of the program the {\em second} time \java{zoop} is invoked.
4158
+
\item Draw a stack diagram that shows the state of the program the {\it second} time \java{zoop} is invoked.
4159
4159
4160
4160
\item What is the complete output?
4161
4161
@@ -4207,7 +4207,7 @@ \section{Exercises}
4207
4207
If $n$ is greater than 2 and $a^n + b^n = c^n$, the program should display ``Holy smokes, Fermat was wrong!''
4208
4208
Otherwise the program should display ``No, that doesn't work.''
4209
4209
4210
-
{\em Hint:} You may want to use \java{Math.pow}.
4210
+
{\it Hint:} You may want to use \java{Math.pow}.
4211
4211
4212
4212
\end{exercise}
4213
4213
@@ -4297,7 +4297,7 @@ \section{Exercises}
4297
4297
Adding a small amount of code at a time, and testing as you go, modify the program so it tells the user whether the guess is too high or too low, and then prompts the user for another guess.
4298
4298
4299
4299
The program should continue until the user gets it right.
4300
-
{\em Hint:} Use two methods, and make one of them recursive.
4300
+
{\it Hint:} Use two methods, and make one of them recursive.
4301
4301
4302
4302
\end{exercise}
4303
4303
@@ -5069,7 +5069,7 @@ \section{Exercises}
5069
5069
x e^{-x} + \sqrt{1 - e^{-x}}
5070
5070
\end{eqnarray*}
5071
5071
%
5072
-
{\em Hint:} The method for raising $e$ to a power is \java{Math.exp}.
5072
+
{\it Hint:} The method for raising $e$ to a power is \java{Math.exp}.
5073
5073
5074
5074
\end{enumerate}
5075
5075
@@ -5160,7 +5160,7 @@ \section{Exercises}
5160
5160
\item Explain in a few words what \java{prod} does (without getting into the details of how it works).
5161
5161
5162
5162
\item Rewrite \java{prod} without the temporary variables \java{recurse} and \java{result}.
5163
-
{\em Hint:} You only need one line for the \java{else} branch.
5163
+
{\it Hint:} You only need one line for the \java{else} branch.
5164
5164
5165
5165
\end{enumerate}
5166
5166
@@ -5200,7 +5200,7 @@ \section{Exercises}
5200
5200
5201
5201
Write a recursive method called \java{power} that takes a double \java{x} and an integer \java{n} and returns $x^n$.
5202
5202
5203
-
{\em Hint:} A recursive definition of this operation is $x^n = x \cdot x^{n-1}$.
5203
+
{\it Hint:} A recursive definition of this operation is $x^n = x \cdot x^{n-1}$.
5204
5204
Also, remember that anything raised to the zeroth power is 1.
5205
5205
5206
5206
Optional challenge: you can make this method more efficient, when \java{n} is even, using $x^n = \left( x^{n/2} \right)^2$.
@@ -6757,12 +6757,12 @@ \section{Exercises}
6757
6757
6758
6758
\begin{exercise}
6759
6759
Write a method named \java{areFactors} that takes an integer \java{n} and an array of integers, and that returns \java{true} if the numbers in the array are all factors of \java{n} (which is to say that \java{n} is divisible by all of them).
6760
-
%{\em Hint:} See Exercise~\ref{ex.isdiv}.
6760
+
%{\it Hint:} See Exercise~\ref{ex.isdiv}.
6761
6761
\end{exercise}
6762
6762
6763
6763
6764
6764
\begin{exercise}
6765
-
Write a method named \java{arePrimeFactors} that takes an integer \java{n} and an array of integers, and that returns \java{true} if the numbers in the array are all prime {\em and} their product is \java{n}.
6765
+
Write a method named \java{arePrimeFactors} that takes an integer \java{n} and an array of integers, and that returns \java{true} if the numbers in the array are all prime {\it and} their product is \java{n}.
6766
6766
\end{exercise}
6767
6767
6768
6768
@@ -6803,7 +6803,7 @@ \section{Exercises}
6803
6803
%You can read about it at \url{https://en.wikipedia.org/wiki/Binary_search_algorithm}.
6804
6804
%
6805
6805
%Write a method called \java{binarySearch} that implements this algorithm.
6806
-
%{\em Hint:} You might find it easier to write this method recursively.
6806
+
%{\it Hint:} You might find it easier to write this method recursively.
6807
6807
%
6808
6808
%\end{exercise}
6809
6809
@@ -9083,7 +9083,7 @@ \section{Exercises}
9083
9083
9084
9084
The implementation of \java{increment} in this chapter is not very efficient.
9085
9085
Can you rewrite it so it doesn't use any loops?
9086
-
{\em Hint:} Remember the modulus operator.
9086
+
{\it Hint:} Remember the modulus operator.
9087
9087
9088
9088
\end{exercise}
9089
9089
@@ -9169,7 +9169,7 @@ \section{Exercises}
9169
9169
\item Write an instance method named \java{reduce} that reduces a rational number to its lowest terms by finding the greatest common divisor (GCD) of the numerator and denominator and dividing through.
9170
9170
This method should be a pure method; it should not modify the instance variables of the object on which it is invoked.
9171
9171
9172
-
{\em Hint:} Finding the GCD only takes a few lines of code.
9172
+
{\it Hint:} Finding the GCD only takes a few lines of code.
9173
9173
Search the web for ``Euclidean algorithm''.
9174
9174
9175
9175
\item Write an instance method called \java{add} that takes a \java{Rational} number as an argument, adds it to \java{this}, and returns a new \java{Rational} object.
@@ -10424,7 +10424,7 @@ \section{Exercises}
10424
10424
\index{StringBuilder}
10425
10425
\index{efficiency}
10426
10426
10427
-
{\em Hint:} You can use the \java{+} operator to concatenate strings, but it is not very efficient.
10427
+
{\it Hint:} You can use the \java{+} operator to concatenate strings, but it is not very efficient.
10428
10428
Consider using \java{java.lang.StringBuilder}; you can find the documentation by doing a web search for ``Java StringBuilder''.
10429
10429
\end{exercise}
10430
10430
@@ -11234,7 +11234,7 @@ \section{Exercises}
11234
11234
Write a loop that plays the game 100 times and keeps track of how many times each player wins.
11235
11235
If you implemented multiple strategies in the previous exercise, you can play them against each other to evaluate which one works best.
11236
11236
11237
-
{\em Hint:} Design a \java{Genius} class that extends \java{Player} and overrides the \java{play} method, and then replace one of the players with a \java{Genius} object.
11237
+
{\it Hint:} Design a \java{Genius} class that extends \java{Player} and overrides the \java{play} method, and then replace one of the players with a \java{Genius} object.
11238
11238
\end{exercise}
11239
11239
11240
11240
@@ -11922,7 +11922,7 @@ \section{Exercises}
11922
11922
Modify {\tt Mickey.java} to draw ears on the ears, and ears on those ears, and more ears all the way down until the smallest ears are only 3 pixels wide.
11923
11923
11924
11924
The result should look like ``Mickey Moose'', shown in Figure~\ref{fig.moose}.
11925
-
{\em Hint:} You should only have to add or modify a few lines of code.
11925
+
{\it Hint:} You should only have to add or modify a few lines of code.
0 commit comments