ch 4 -5

Ace your homework & exams now with Quizwiz!

When you pass the name of a file to the PrintWriter constructor and the file already exists, it will be erased and a new empty file with the same name will be created T or F

True

You can use the PrintWriter class to open a file and write data to it. T or F

True

When a character is stored in memory, it is actually the ________ that is stored.

Unicode number

Java requires that the boolean expression being tested by an if statement be enclosed in

a set of parentheses.

In all but very rare cases, loops must contain, within themselves

a way to terminate.

In general, there are two types of files which are

text and binary.

Which of the following is the method you can use to determine whether a file exists?

the File class's exists method

A flag may have the values

true or false

What will be the values of x and y as a result of the following code? int x = 25 , y = 8; x += y++;

x = 33, y = 9

What will be the value of x after the following code is executed? int x, y = 15;

15

What will be displayed after the following statements are executed? int hours = 30; double pay , payRate = 10.00; pay = hours <= 40 ? hpurs*payRate : hours*payRate * 2.0

300.00

What will be the value of x after the following statements are executed? int x = 10; for (int y = 5; y < 20; y+=5) x+=y;

40

What will be the value of ans after the following statements are executed? int x = 40; int y = 40; if (x=y) ans = x + 10;

The code contains an error and will not compile.

What will be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A': discountRate = 0.08; case 'B': discountRate = 0.06; case 'C': discountRate = 0.04; default: discountRate = 0.0;

0.0

How many times will the following do-while loop be executed? int x = 11; do { x += 20; }while (x>100);

1

What will be the value of x after the following code is executed? int x = 10; while (x < 100) { x += 100; }

100

How many times will the following for loop be executed? for (int count = 10; count <= 21; count++) System.out.println("Java is great!");

12

A random number, created as an object of the Random class, is always an integer. T or F

False

In a for loop, the control variable is always incremented.

False

The DecimalFormat class is part of the Java API so it is automatically available to your programs. T or F

False

The for loop is a posttest loop that has built-in expressions for initializing, testing, and updating. T or F

False

When two strings are compared using the String class's compareTo method, the comparison is not case sensitive T or F

False

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents? FileWriter fwriter = new FileWriter("MyFile.txt"); PrintWriter outFile = new PrintWriter(fwriter); PrintWriter outfile = new PrintWriter(true, "MyFile.txt"); PrintWriter outfile = new PrintWriter("MyFile.txt", true); FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

FileWriter fwriter = new FileWriter("MyFile.txt", true);PrintWriter outFile = new PrintWriter(fwriter);

The ________ loop is ideal in situations where the exact number of iterations is known.

For

What does the following code do? Scanner keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrinterWriter outFile = new PrintWriter(filename);

It allows the user to enter the name of the file that data will be written to

A loop that executes as long as a particular condition exists is called a(n) ________ loop.

conditional

A ________ is a boolean variable that signals when some condition exists in the program.

flag


Related study sets

Module 6: Home Safety & the Aging Adult: Elderly Client's Home

View Set

Introduction to Human Resource Management

View Set

Muscle, Origin, Insertion, Action, Blood, Nerve of Brachium Musculature

View Set

Chapter 49: Drugs Used to Treat Anemias (COMBINED)

View Set

Unit 2: Cell Structure and Function

View Set

Personal Career Development Ch. 2

View Set

KINE: 3000 Early Motor Development Ch.6

View Set

CHEM 3375 Learning Curves Chapters: 1,2,3,4,5,6,7,10

View Set

Systems Analysis and Design- Ch 3

View Set