Programming and Problem Solving with Java

(やまだぃちぅ) #1
715


  1. a. The output is BCDE.


b.inLine = inFile.readLine();
count = 0 ;
while(count < inLine.length())
{
outFile.print(inLine.charAt(count));
count++;
}
outFile.println();
14.Yes, this code segment needs a priming read.


datum = inFile.readLine();
while(datum != null)
{
letter = datum.charAt( 0 );
count = 0 ;
while(count < datum.length())
{
outFile.print(letter);
count++;
letter = datum.charAt(count);
}
outFile.println();
datum = inFile.readLine();
outFile.println("Another line read...");
}
18.Written



  1. a. Count-controlled and event-controlled.


b.A count-controlled loop executes a predetermined number of times. An event-
controlled loop executes as long as an event is true and exits the loop when the
event becomes false.
c. The loop runs forever (or until the program is manually terminated by the op-
erating system).
d.The loop runs forever (or until the program is manually terminated by the op-
erating system).
e.Sentinel-controlled, end-of-file-controlled, and flag-controlled.


  1. a. An assignment expression is an expression containing an assignment
    operator.
    b.((line = dataFile.readLine())!=null)

Free download pdf