1.7
b r e a k
is used to exit a loop. A labelled
b r e a k
exits the loop that is marked with a label.
b r e a k
is also
used to exit a
s w i t c h
statement, rather than stepping through to the next case.
1.8 The
c o n t i n u e
statement is used to advance to the next iteration of the loop.
1.9 Method overloading allows the reuse of a method name in the same scope as long as the signatures
(parameter list types) of the methods differ.
1.10 In call-by-value, the actual arguments are copied into the method’s formal parameters. Thus, changes
to the values of the formal parameters do not affect the values of the actual arguments.
In Theory
1.11 After line 1,
b
is 6,
c
is 9, and
a
is 13. After line 2,
b
is 7,
c
is 10, and
a
is 16. After line 3,
b
is 8,
c
is
11, and
d
is 18. After line 4,
b
is 9,
c
is 12, and
d
is 21.
1.12 The result is
t r u e
. Note that the precedence rules imply that the expression is evaluated as
(true&&false) || true
.
1.13 The behavior is different if
s t a t e m e n t s
contains a
c o n t i n u e
statement.
1.14 Because of call-by-value,
x
must be 0 after the call to method
f
. Thus the only possible output is
0
.
In Practice
1.15 An equivalent statement is:
while( true )
s t a t e m e n t
1.16 This question is harder than it looks because I/O facilities are limited, making it difficult to align
columns.
public class MultiplicationTable
{
public static void main( String [ ] args )
{
for( int i = 1; i < 10; i++ )
{
for( int j = 1; j < 10; j++ )
{
if( i * j < 10 )
System.out.print( “ “ );
System.out.print( i * j + “ “ );
}
System.out.println( );
}
}
}
1.17 The methods are shown below (without a supporting class); we assume that this is placed in a class
that already provides the
m a x
method for two parameters.
public static int max( int a, int b, int c )
{
return max( max( a, b ), c );
}
2