Java Chapters 4&5

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

A loop that repeats a specific number of times is known as a(n) ________ loop.

count-controlled

In an if-else statement, if the boolean expression is false the statement or block following the _____ is executed.

else

You can use the File class's ______ method to determine whether a file exists.

exists

A flag may have the values

true or false

The boolean expression in an if statement must evaluate to

true or false

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

unicode number

Assume that inputFile references a Scanner object that was used to open a file. Write the beginning of a while loop that shows the correct way to read data from the file until the end of the file is reached.

while (inputFile.hasNext())

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

15

What will be displayed when the following code is executed? double x = 45678.259; DecimalFormat formatter = new DecimalFormat("#,###,##0.00); JOptionPane.showMessageDialog(null,formatter.format(x));

45,678.26

2. What does the following code do? Scanner keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrintWriter outFile = new PrintWriter(filename); A) It writes to a file named filename. B) It allows the user to enter the name of the file that data will to be written to. C) It establishes a connection with a file named filename. D) Nothing. The code contains a syntax error.

A

Given the following statement, write the statements that will write the string "Calvin" to the file DiskFile.txt? (use diskOut as the out-file variable)

PrintWriter diskOut = new PrintWriter("DiskFile.txt"); diskOut.println("Calvin");

The variable used to keep the running total is called a(n)

accumulator

Enclosing a group of statements inside a set of braces creates a ______ of statements.

block

A block of code is enclosed in a set of

braces

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

conditional

In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression. (true/false)

false

The for loop is a posttest loop that has built-in expressions for initializing, testing, and updating. (true/false)

false

When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration. (true/false)

false

When the continue statement is encountered in a loop, all the statements in the body of the loop that appear after it are executed, and the loop prepares for the next iteration. (true/false)

false

When two strings are compared using the String class's compareTo method, the comparison is case-insensitive. (true/false)

false

The ________ statement is used to create a decision structure, which allows a program to have more than one path of execution.

if

If a loop does not contain within itself a way to terminate, it is called an

infinite loop

Assuming that inputFile references a Scanner object that was used to open a file, write a statement that will read an int from the file.

int number = inputFile.nextInt();

Java requires that the boolean expression being tested by an if statement be enclosed in a set of _________.

parentheses

This type of loop will always be executed at least once.

posttest

________ operators are used to determine whether a specific relationship exists between two values.

relational

A ________ is a value that signals when the end of a list of values has been reached.

sentinel

A(n) ________ is a special value that cannot be mistaken as a member of a list of data items and signals that there are no more data items from the list to be processed.

sentinel

Write the expression that could be used to perform a case-insensitive comparison of two String objects named str1 and str2.

str1.equalsIgnoreCase(str2)

In all but rare cases, loops must contain within themselves a way to ________.

terminate

In general, there are two types of files:

text and binary

"000.0" could be passed to the DecimalFormat constructor to display 12.78 as 012.8? (true/false)

true

(chrA != 'A') determines whether the char variable chrA is not equal to the letter 'A' (true/false)

true

A file must always be opened before using it and closed when the program is finished using it. (true/false)

true

A local variable's scope always ends at the closing brace of the block of code in which it is declared. (true/false)

true

All it takes for an OR expression to be true is for one of the subexpressions to be true. (true/false)

true

Before entering a loop to compute a running total, the program should first set the accumulator variable to an initial value, usually zero. (true/false)

true

File file=new File("MyFile.txt"); Scanner inputFile=new Scanner(file); The above statement opens a file named MyFile.txt and allows you to read data from it. (true/false)

true

FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter); These statements open a file named MyFile.txt and allows you to append data to its existing contents. (true/false)

true

If the expression on the left side of the && operator is false, the expression on the right side will not be checked. (true/false)

true

The do-while loop is ideal in situations where you always want the loop to iterate at least once. (true/false)

true

When you open a file with the PrintWriter class, the class can potentially throw an IOException. (true/false)

true

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. (true/false)

true

You can use the PrintWriter class to open a file and write data to it. (true/false)

true


संबंधित स्टडी सेट्स

Advanced Children and Families Final

View Set

Chapter 38: Assessment and Management of Patients With Rheumatic Disorders Prep-U

View Set

Economics Chapter 9, ECON 131 Final, Ch 16 Review, AP Macro Econ Ch 15 & 16, Test Practice Questions (Exam 3), Chapter 10 Macro Review, Macro Final

View Set

Information Technologies Midterm Practice 2 (ch 5, 4 & 7)

View Set

Art Appreciation Exam 2 Study Guide

View Set

Configuring Windows Server 2019 for MindTap/Cengage

View Set