This website is preserved for historical and scholarly reference and is no longer actively maintained.
QUIZ 20
October 6, 1997
#1. In the following code, what does the function named subProg do? i.e., what task does the function accomplish? (Do NOT describe the internal logic of the code.) ( 4 points )
import ccj.*;
public class ST2
{
public static void main (String [ ] args)
{
double x = 8;
double y = subProg ( x );
System.out.println ("y = " + y );
}
public static double subProg ( double a )
{
if ( a <= 0 ) return 0;
double xnew = a / 2;
double xold;
do
{
xold = xnew;
xnew = ( xold + a / xold ) / 2;
} while (Numeric.compareDoubles(xnew, xold) != 0 )
return xnew;
}
}
#2. Your program is named ST1 and begins:
import ccj.*;
public class ST1
{
public static void main (String [ ] args)
{ ...
Explain what the command
is used for. What is in test1.in? What is the purpose of this command? ( 3 points )
#3. What is the purpose of a "throw" statement as used in Chapter 7? ( 3 points )