472
18.A breakstatement located inside a switchstatement that is located within a
whileloop causes control to exit the loop immediately. (True or False?)
19.Classify each of the following as either an expression or an expression
statement.
a.sum = 0
b.sqrt(x)
c. y = 17 ;
d.count++
20.Rewrite each statement as described.
a.Using the +=operator, rewrite the statement
sumOfSquares = sumOfSquares + x * x;
b.Using the decrement operator, rewrite the statement
count = count – 1 ;
c. Using a single assignment statement that uses the ?:operator, rewrite the
statement
if(n > 8 )
k = 32 ;
else
k = 15 * n;
Programming Warm-Up Exercises
- a.Declare an exception of the class MyException.
b.Write the class MyException.
c. Write the statement that throws an exception of class MyException.
2.Write a try-catchstatement that attempts to open the file data.infor reading
and writes an error message if an exception is thrown.
3.Write a switchstatement that does the following:
If the value of grade(a variable of type char) is
‘A’, add 4 to sum
‘B’, add 3 to sum
‘C’, add 2 to sum
‘D’, add 1 to sum
‘F’, print “Student is on probation” on the PrintWriterfile outData
4.Modify the code you wrote for Exercise 3 so that an error message is printed if
gradedoes not equal one of the five possible grades.