forked from sergutsan/groovyck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextra.tex
More file actions
89 lines (71 loc) · 2.8 KB
/
Copy pathextra.tex
File metadata and controls
89 lines (71 loc) · 2.8 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
\section{Extra exercises}
\label{sec:additional-exercises}
This section provides some additional exercises for you, for more
practice with Groovy.
\subsection*{Exercise X1}
What does this program do?
\VerbatimInput[frame=single,label=Example]{src/s3Example6.groovy}
\subsection*{Exercise X2}
If you have worked out what the above program does, can you
see that, for certain series of numbers, it will not produce the correct
output? In what circumstances will it not work correctly, and how could
you change the program to make it work properly?
\subsection*{Exercise X3}
Write a program that takes a series of numbers (ending in 0) and counts
the number of times that the number 100 appears in the list. For example,
for the series 2, 6, 100, 50, 101, 100, 88, 0, it would output 2.
\subsection*{Exercise X4}
Write a program that takes a series of lines of text (ending by
an empty string) and,
at the end, outputs the longest line.
You may assume there is at least one line in the input.
\subsection*{Exercise X5 (this one is a bit harder)}
Write a program that takes
a series of numbers (ending in 0). If the
current number is the same as the previous number, it says ``Same'';
if the current number is greater than the previous one, it says ``Up'',
and if it's less than the previous one, it says ``Down''.
It makes no response at all to the
very first number. For example, its output for the list 9, 9, 8, 5,
10, 10, 0,
would be Same, Down, Down, Up, Same
(comparing, in turn, 9 and 9, 9 and 8, 8 and 5, 5 and 10, 10 and 10).
You may assume there are at least two numbers in the input.
\begin{verbatim}
Enter the first number: 9
Enter the next number (0 to finish): 9
Same
Enter the next number (0 to finish): 8
Down
Enter the next number (0 to finish): 5
Down
Enter the next number (0 to finish): 10
Up
Enter the next number (0 to finish): 10
Same
Enter the next number (0 to finish): 0
\end{verbatim}
\subsection*{Exercise X5bis (still a bit harder)}
Write a solution for exercise X5 that prints all the ``Down'',
``Same'', and ``Up'' messages together at the end.
\begin{verbatim}
Enter the first number: 3
Enter the next number (0 to finish): 5
Enter the next number (0 to finish): 4
Enter the next number (0 to finish): 4
Enter the next number (0 to finish): 6
Enter the next number (0 to finish): 8
Enter the next number (0 to finish): 2
Enter the next number (0 to finish): 6
Enter the next number (0 to finish): 7
Enter the next number (0 to finish): 5
Enter the next number (0 to finish): 6
Enter the next number (0 to finish): 6
Enter the next number (0 to finish): 7
Enter the next number (0 to finish): 0
Up Down Same Up Up Down Up Up Down Up Same Up
\end{verbatim}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "main"
%%% End: