Programming Java Chapter 5 (2)

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

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

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

5

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

Numbers in the range 100 - 500

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

True

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

210

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

This is an infinite loop

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.

counter-controlled loop

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

diskOut.println("Calvin");

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");

Loop control variable

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

5, 8, 11, 14,

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

28

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

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

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

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");

The File class's exists method

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


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

South America Realm/ Regions Test

View Set

Lección 9: Estructura: 9.1, 9.2, 9.3, y 9.4

View Set

African Americans - The New Deal

View Set

EMT Chapter 27 Face and Neck Injuries

View Set

rad physics homework questions quiz

View Set