263
6.Write a code fragment that reads a line from fileInand stores the first two
characters into two charvariables firstand second.(fileInis of the class
BufferedReaderand has been declared and assigned.)
7.Write a code fragment that reads a line from fileInBufand prints it on
fileOutPrwith blank lines before and after it.
8.Write the statements that close fileOutand then associate it with the file
dataOut.dat.
9.Write an application segment that sets a booleanvariable dangerousto trueand
stops reading data if pressure(a floatvariable being read in) exceeds 510.0. Use
dangerousas a flag to control the loop.
10.Here is a simple count-controlled loop:
count = 1 ;
while(count < 20 )
count++;
a.List three ways of changing the loop so that it executes 20 times instead of
19.
b.Which of those changes makes the value of countrange from 1 through 21?
11.Write an application segment that counts the number of times the integer 28
occurs in a file of 100 integers.
12.Write a nested loop code segment that produces this output:
1
1 2
1 2 3
1 2 3 4
13.Write a code segment that reads a file of student scores for a class (any size)
and finds the class average.
14.Write a code segment that reads in integers and then counts and prints the
number of positive integers and the number of negative integers. If a value is
zero, it should not be counted. The process should continue until end-of-file
occurs.
15.Write a code segment that adds the even integers from 16 through 26,
inclusive.
16.Write a statement(s) that increments countby 1 and sets it back to 0 when it
reaches 13.
17.Write an application segment that prints out the sequence of all the hour and
minute combinations in a day, starting with 1:00 A.M. and ending with 12:59
A.M.