INFO-I210 Midterm 2 Review (with quizzes)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

To document the return value of a method you can use a ________.

@return tag

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; }

110

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

12

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

15

What will be returned from the following method? public static double methodA () { double a= 8.5 + 9.5; return a; }

18.0

What will be printed after the following code is executed? for (int number=5; number <=15; number += 3) System.out.println(number + " , ";

5, 8, 11, 14

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?

Control is returned to method C.

Which of the following statements opens a file named MyFile.txt and allows you to read data from it?

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

In the following code, what values could be read into number to terminate the while loop?

Numbers in the range 100 - 500

When a method tests an argument and returns a true or false value, it should return ________.

a boolean value

In the following code, Integer.parseInt(str) is an example of ________.int num;string str = "555";num = Integer.parseInt(str) + 5;

a value-returning method

Given the following method static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n--; } } What is the printout of the call nPrint("a", 4)?

a. aaaa

When an object, such as a String, is passed as an argument it is ________.

actually a reference to the object that is passed

All @param tags in a method's documentation must ________.

appear after the general description of the method

Values that are sent into a method are called ________.

arguments

Suppose your method does not return any value, which of the following keywords can be used as a return type?

c. void

) The following loop displays ________. for (int i = 1; i <= 10; i++) { System.out.print(i + " "); }

d. 1 2 3 4 5 6 7 8 9 10

When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as ________.

d. pass by value

The ________ loop is ideal in situations where you always want the loop to iterate at least once.

do-while

T or F- In a for loop, the control variable is always incremented.

false

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

int number = inputFile.nextInt();

Assume that the following method header is for a method in class A. public void displayValue(int value) Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method?

int x = 7; displayValue(x);

Each repetition of a loop is known as a(n) ________.

iteration

When an argument is passed to a method ________.

its value is copied into the method's parameter variable

You should always document a method by writing comments that appear ________.

just before the method's definition

A method ________.

may have zero or more parameters

Which of the following expressions will generate a random number in the range of 1 through 10?

myNumber = randomNumbers.nextInt(10) + 1;

A special variable that holds a value being passed into a method is called a(n) ________.

parameter

In the header, the method name is always followed by ________.

parentheses

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 to be processed.

sentinel

Given the following method, which of these method calls is valid?

showProduct(10, 4.5);

The process of breaking a problem down into smaller pieces is sometimes called ________.

the divide and conquer method

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

this is an infinite loop

T or F- A variable defined inside a method is referred to as a local variable.

true

T or F- Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.

true

T or F- Methods are commonly used to break a problem into small manageable pieces.

true

T or F- The do-while loop must be terminated with a semicolon.

true

T or F- The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true.

true

T or F- Two general categories of methods are void methods and value-returning methods.

true

T or F- 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

T or F- 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

T or F- You must have a return statement in a non-void method.

true

T or F- You must have a return statement in a value-returning method.

true

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached?

while (inputFile.hasNext()) { ... }

Which of the following are pre-test loops?

while, for


Set pelajaran terkait

AP Psychology Exam Review - REVISED, AP Exam Review - 2020

View Set

LAB 11 (Lung Volumes and Capacities)

View Set

Police Problems and Practices Test 1

View Set

Intro to Criminal Justice Final Exam

View Set

Chapter 16 Property and Its Acquisition

View Set

Macroeconomics: Chapter 7 Practice

View Set