714
9.// This is a nonsense program segment
if(a > 0 )
if(a < 20 )
{
System.out.print("A is in range.");
b = 5 ;
}
else
{
System.out.print("A is too large.");
b = 3 ;
}
else
System.out.print("A is too small.");
System.out.print("All done.")
11.discriminant = b * b - 4.0* a * c;
if(discriminant < 0.0)
System.out.println("No real roots.");
else
{
root1 = (-b - discriminant) / (2.0* a);
root2 = (-b + discriminant) / (2.0* a);
}
Chapter 5 Exam Preparation Exercises
1.
4.It skips the next 1,000 characters in the file. If EOF is reached first, an exception is
thrown.
7.Loops are segments of code that are repeated from zero to many times as long as
an expression is true. Branches are segments of code that may be executed zero or
one time, depending on the value of an expression.
9.number = 1 ;
while(number < 11 )
{
out.println(number);
number++;
}
Import the library package java.io.*
Declare a file variable
Instantiate the file object and assign its address to the file variable
Use methods associated with the file object to read or write
Call a method to close the file