Programming and Problem Solving with Java

(やまだぃちぅ) #1
727

case'B': sum = sum + 3 ;
break;
case'C': sum = sum + 2 ;
break;
case'D': sum++;
break;
case'F': outData.println("Student is on probation");
break;
default : outData.println("Invalid letter grade");
break; // Not required
}
6.response = Integer.parseInt(inData.readLine());
if(response >= 0 && response <= 127 )
do
{
response = Integer.parseInt(inData.readLine());
} while(response >= 0 && response <= 127 );
10.k = 9;
do
{
outData.println(k + " "+ 3 * k);
k++;
} while(k <= 21 );
11.public intpower(intbase, intexponent)
// Return base raised to the exponent power
{
intpowerValue = 1 ;
for(int i = 1 ; i <= exponent; i++)
powerValue = powerValue * base;
returnpowerValue;
}

Chapter 10 Exam Preparation Exercises



  1. a.float[] floatArray = new float[ 24 ];
    b.int[] intArray = new int[ 500 ];
    c. double[] doubleArray = new double[ 50 ];
    d.char[] charArray = new char[ 10 ];


  2. a.Because the array is of type int, the values are automatically set to 0 by the
    constructor.
    b.for(intindex = 0 ; index < count.length; count++)
    count[index] =
    Integer.parseInt(inFile.readLine());



Free download pdf