Programming exam (chapters 4 & 5)

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

The variable used to keep the running total is called a(n) A) summation. B) accumulator. C) integer. D) sentinel.

B) accumulator

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 allows the user to enter the name of the file that data will to be written to. B) It writes to a file named filename. C) It establishes a connection with a file named filename. D) Nothing. The code contains a syntax error.

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

The if/else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false. A) True B) False

A) True

In Java, when a character is stored in memory, it is actually as a(n) ________. A) Unicode character code B) ASCII character code C)EBCDIC character code D) Morse Code

A) Unicode character code

A block of code is enclosed in a set of A) braces B) parentheses C) double quotes D) brackets

A) braces

This type of loop will always be executed at least once. A) conditional B) infinite C) pretest D) posttest

A) conditional

This is an item that separates other items. A) delimiter B) partition C) terminator D) sentinel

A) delimiter

The ________ is ideal in situations where the exact number of iterations is known. A) do-while loop B) while loop C) for loop D) posttest loop

A) do-while loop

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read anint from the file? A) int number = inputFile.nextInt(); B) int number = inputFile.readInt(); C) int number = inputFile.next(); D) int number = inputFile.integer();

A) int number = inputFile.nextInt();

A ________ is a value that signals when the end of a list of values has been reached. A) sentinel B) terminal C) delimiter D) token

A) snetinal

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

A) true

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

B) 100

What will be the value of ans after the following code has been executed? int x = 65; int y = 55; if (x>= y) int ans = x + y; A) 10 B) 120 C) 100 D) No value, there is a syntax error

B) 120

What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x>y) x = x - y; A) 75 B) 15 C) 60 D) 135

B) 15

What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10; x += 15; case 12; x-= 5; default: x *= 3; A) 5 B) 20 C) 25 D) 30

B) 20

What will be the value of x after the following code is executed? int x = 10, y = 20; while (y< 10) { x += y; y += 20; } A) 90 B) 210 C) 110 D) 130

B) 210

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

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

In all but rare cases, loops must contain within themselves A) nested loops. B) a way to terminate. C) arithmetic operators. D) if statements.

B) a way to terminate.

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if ( x >= y) { ans = x + 10; x-=y; } else { ans = y + 10; y += x; } A) ans = 60, x = 50, y = 100 B) ans = 60, x = 0, y = 50 C) ans = 45, x = 50, y = 0 D) ans = 45, x = 50, y = 50

B) ans = 60, x = 0, y = 50

When testing for character values, the switch statement does not test for the case of the character. A) true B) false

B) false

When working with the PrintWriter class, which of the following import statements should you have near the top of your program? A) import java.file.*; B) import java.io.*; C) import javax.swing.*; D) import javac.io.*;

B) import java.io.*;

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. A) delimiter B) sentinel C) accumulator D) terminator

B) sentinel

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000? A) ((x >= 500 && x <= 650) && (y != 1000)) B) ((x > 500 AND x < 650) OR !(y.equal(1000))) C) ((x > 500 && x < 650) || (y != 1000)) D) ((x < 500 && x > 650) || !(y == 1000))

C) ((x > 500 && x < 650) || (y != 1000))

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x <= 100); A) 3 B) 5 C) 1 D) 4

C) 1

What will be the value of x after the following code is executed? int x, y = 15; x = y--; A) 0 B) 14 C) 15 D) 16

C) 15

What would be the value of bonus after the following statements are executed? int bonus, sales = 1250; if (sales > 1000) bonus = 100; if (sales > 750) bonus = 50; if (sales > 500) bonus = 25; else bonus = 0; A) 100 B) 500 C) 25 D) 0

C) 25

If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2? (1) (str1 < str2) (2) (str1.equals(str2) < 0) (3) (str1.compareTo(str2) < 0) A) 1, 2, and 3 will all work B) 2 C) 3 D) 2 and 3

C) 3

What will be printed when the following code is executed? double x = 45678.259; DecimalFormat formatter = new DeciamlFormat ("#,###,##0.00"); System.out.println(formatter.format(x)); A) 45678.259 B) 0,045,678.26 C) 45,678.26 D) 45,678.3

C) 45,678.26

Before entering a loop to compute a running total, the program should first A) set all variables to zero. B) know exactly how many values there are to total. C) set the accumulator variable to an initial value, usually zero. D) read all the values into main memory.

C) set the accumulator variable to an initial value, usually zero.

In general, there are two types of files: A) static and dynamic. B) encrypted and unencrypted. C) text and binary. D) delimited and unlimited.

C) text and binary.

You can use this method to determine whether a file exists. A) the File class's canOpen method B) the Scanner class's exists method C) the File class's exists method D) the PrintWriter class's fileExists method

C) the File class's exists method

Which of the following expressions will determine whether x is less than or equal to y? A) x > y B) x =< y C) x <= y d) x >= y

C) x <= y

The ________ statement is used to make simple decisions in Java. A) do-while B) for C) switch D) if

D) if

Which of the following will format 12.78 to display as 12.8%? A) 000.0% B) #0.00% C) ###.##% D) ##0.0%

D) ##0.0%

What will be the value of bonus after the following code is executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales<10000) bonus = 750; else if (sales < 20000) bonus = 1000 else bonus = 1250; A) 200 B) 500 C) 750 D) 1000 E) 1250

D) 1000

What will be the value of pay after the following statements are executed? int hours = 45; double pay, payRate = 10.00; pay = hours <= 40 ? hours * payRate: 40 * payRate + (hours - 40) * payRate * 1.5; A) 400.00 B)450.00 C)465.00 D)475.00

D) 475.00

A for loop normally performs which of these steps? A) Test the control variable by comparing it to a maximum/minimum value and terminate when the variable reaches that value B) Initialize a control variable to a starting value C) Update the control variable during each iteration D) All of the above

D) All of these

To do a case insensitive compare which of the following expressions could be used to test the equality of two strings, str1 and str2? A) (str1.equalsIgnoreCase(str2)) B) (str1.compareToIgnoreCase(str2) == 0) C) Only (str1.equalsIgnoreCase(str2)) D) Both (str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2) == 0)

D) Both (str1.equalsIgnoreCase(str2)) and (str1.compareToIgnoreCase(str2) == 0)

An important style rule you should adopt for writing if statements is to write the conditionally executed statement on the line after the if statement. A) true B) false

A) true

What will be the value of x after the following code is executed? int x = 10; for ( int y = 5; y < 20; y += 5) x += y; A)40 B)50 C)25 D)30

A)40


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

Block 9: Peds Module 1-5 practice questions

View Set

Geology Final: Practice Questions

View Set

Microecon - Chapter 10 Concept Quiz

View Set

Chapter 10.3-The Growth of European Kingdoms-Emily Schommer

View Set

Patho Chapter 20 disorders of brain function

View Set