Java Reference
In-Depth Information
23.
Suppose that
infile
is a
Scanner
object associated with the file that
contains the following data:
27306 savings 7503.35
. Write the Java
statements that read and store the first input in the
int
variable
acctNum-
ber
, the second input in the
String
variable
accountType
, and the third
input in the
double
variable
balance
.
24.
Suppose that you have the following statements:
PrintWriter outfile;
double
distance = 375;
double
speed = 58;
double
travelTime;
Write Java statements to do the following:
a.
Open the file
travel.dat
using the variable
outfile
.
b.
Write the values of the variables
distance
and
speed
, to two decimal
places, in the file
travel.dat
.
c.
Calculate and write the
travelTime
, to two decimal places, in the file
travel.dat
.
25.
A program reads data from a file called
inputFile.dat
and, after doing
some calculations, writes the results to a file called
outFile.dat
. Answer
the following questions:
3
a.
After
the program executes, what are the contents of
the file
inputFile.dat
?
b.
After the program executes, what are the contents of the file
outFile.dat
if this file was empty before the program executed?
c.
After the program executes, what are the contents of the file
outFile.dat
if this file contained 100 numbers before the program executed?
d.
What would happen if the file
outFile.dat
did not exist before the
program executed?
1.
Consider the following incomplete Java program:
public class
Ch3_PrExercise1
{
public static void
main(String[] args)
{
.
.
.
}
}
Search WWH ::
Custom Search