Programming Java Chapter 5 (2)

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

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

210

What will be the value of x after the following code is executed? int x, y = 4, z = 6; x = (y++) * (++z); -24 -28 -30 -35

28

What will be the value of x after the following code is executed? int x = 10; while (x < 100); { x += 10; } -90 -100 -110 -This is an infinite loop

This is an infinite loop

What will be the value of x after the following code is executed? int x = 10; do { x *= 20; } while (x > 5); -10 -200 -This is an infinite loop. -The loop will not be executed, the initial value of x > 5.

This is an infinite loop.

Java provides a set of simple unary operators designed just for incrementing and decrementing variables. True or False

True

When the continue 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 or False

True

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

5

What will be printed after the following code is executed? for (int number = 5; number <= 15; number +=3) System.out.print(number + ", "); -5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -5, 8, 11, 14, 17, -5, 8, 11, 14, -This is an invalid for statement

5, 8, 11, 14,

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

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

Before entering a loop to compute a running total, the program should first do this. -Read all the values into main memory -Set the accumulator where the total will be kept to an initial value, usually zero -Know exactly how many values there are to total -Set all variables to zero

Set the accumulator where the total will be kept to an initial value, usually zero

A loop that repeats a specific number of times is known as a(n) -sentinel loop -conditional loop -counter-controlled loop -infinite loop

counter-controlled loop

This variable controls the number of times that the loop iterates. -Counter variable -Loop control variable -Running total -Decrement variable

Loop control variable

In the following code, what values could be read into number to terminate the while loop? Scanner keyboard = new Scanner(System.in); System.out.print("Enter a number: "); int number = keyboard.nextInt(); while (number < 100 || number > 500) { System.out.print("Enter another number: "); number = keyboard.nextInt(); } -Numbers less than 100 -Numbers greater than 500 -Numbers in the range 100 - 499 -Numbers in the range 100 - 500

Numbers in the range 100 - 500

You can use this method to determine whether a file exists. -The Scanner class's exists method -The File class's exists method -The File class's canOpen method -The PrintWriter class's fileExists method

The File class's exists method

Given the following statement, which statement will write "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt"); -System.out.println(diskOut, "Calvin"); -DiskFile.println("Calvin"); -PrintWriter.println("Calvin"); -diskOut.println("Calvin");

diskOut.println("Calvin");


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

Adaptive Quizzing- Care of the Newborn

View Set

Unit 11: Add and Subtract Fractions with Unequal Denominators

View Set

Cardiac output and venous return

View Set

AP Computer Science Semester 2 Final Exam

View Set

Physical Therapy Quiz/Test Answers

View Set