Programming and Problem Solving with Java

(やまだぃちぅ) #1

260


13.The following code segment is supposed to copy one line from the file inFileto
the file outFile.
inLine = inFile.readLine();
count = 1 ;
while(count < inLine.length())
{
outFile.print(inLine.charAt(count));
count++;
}
outFile.println();
a.What is the output if the input line consists of the characters ABCDE?
b.Rewrite the code so that it works properly.
14.Does the following code segment need any priming reads? If not, explain why.
If so, add the input statement(s) in the proper place. (letteris of type char.)
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 ...");
}
15.What sentinel value would you choose for an application that reads telephone
numbers as integers?
16.Consider the following code segment:
sum = 0 ;
i = 1 ;
limit = 8 ;
finished = false;

T


E


A


M


F


L


Y


Team-Fly®

Free download pdf