COP exam 2

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

What is the missing statement below in the for loop that would make the loop iterate 5 times. for (i = 2; _________ i++) { ...... }

i < 7;

What is the output of the following Java code? int num = 14; while (num <= 32) num = num + 10; System.out.println( num );

34

public int mystery(int x, int y) { if (x >= y) return x - y; else return x + y; } Based on the code above, what would be the output of the following statement? System.out.println(mystery(8, mystery(2, 1));

7

A(n) ____ causes a value to be sent from a called method back to the calling method.

return statement

public static double secret(int first, double second) { double temp; if (second > first) temp = first * second; else temp = first - second; return temp; } What is the name of the above method?

secret

public static double secret(int first, double second) { double temp; if (second > first) temp = first * second; else temp = first - second; return temp; } Which of the following is a valid call statement to the method given above?

secret(5, 4.8);

A car presents an abstraction to a user, including a steering wheel, gas pedal, and brake. T or F

true

A method body provides information about how other methods can interact with it. T or F

true

An accessor method accesses fields but may not modify a class' fields. T or F

true

An application's main() method must have a void return type. T or F

true

In Java, a two-dimensional array is actually an array of references to one-dimensional arrays. T or F

true

The statement int[][] scaleFactor = { {5, 2, 8, -2}, {6, 0, 1, 7} }; is a valid statement for declaring and initializing the scaleFactor array. T or F

true

The values in an array are accessed by an index, whereas the values in a class are accessed by name. T or F

true

After execution of the code fragment int[] arr = new int[5]; int i; for (i = 0; i < 5; i++) { arr[i] = i + 2; if (i >= 3) arr[i-1] = arr[i] + 3; } what is contained in arr[1]?

3

What is the output of the following Java code? int count; int num = 2; for (count = 1; count < 4; count++){ num = num + 3; System.out.print(num + " ");} System.out.println();

5 8 11

What is the output of the following program fragment? int[] alpha = {100, 200, 300, 400, 500}; int i; for (i = 4; i >= 0; i--) System.out.print(alpha[i] + " ");

500 400 300 200 100

What is the output of the following program fragment? int[] gamma = {5, 10, 15}; for (int count = 0; count < 3; count++)System.out.print(":" + gamma[count]);

:5:10:15

What statement is required to enable a user to utilize the String class?

Nothing; Strings are already imported

What is the output of the following Java code? int count = 6;System.out.print("Sem");do{ System.out.print('i'); count--;}while (count >= 5);System.out.println("nole");

Semiinole

Which of the following is true about a while loop?

The body of the loop may not execute at all.

Given the declaration int[][] score = new int[5][8]; which of the following outputs the array components in row order?

for (i = 0; i < 5; i++) for (j = 0; j < 8; j++) System.print(score[i][j]);

When a variable ceases to exist at the end of a method, programmers say the variable ____.

goes out of scope

Which operator explicitly allocates an object of the specified class type?

new

What is the output of the following Java code?int num = 15;while (num > 0)num = num - 3;System.out.println(num);

0

What is the result of the following program? public class FindMax { public static void main (String [ ] args) { int max = 0; max (1, 2, max); System.out.println(max); }//end of main method public static void max (int value1, int value2, int max) { if(value1 > value2) max = value1; else max = value2; }//end of max method }//end of class

0

What are the contents of arr after the for loop? int j = 0; for (i = 0; i < 5; i++) { arr[i] = i + j;j = j + 1; }

0,2,4,6,8

public int mystery(int x, int y) { if (x >= y) return x - y; else return x + y; } Based on the code above, what would be the output of the following statement? System.out.println(mystery(8,7));

1

What is the result of the following code segment? for (int i = 1; i <= 12; i++) { System.out.print(i + " "); i++;}

1 3 5 7 9 11

How many times will the following code print "Florida State University"? int count = 0; while (count < 10) { System.out.println("Welcome to Java"); count++; }//end of while loop

10

Which of the following loops prints "Welcome to Java" 10 times? A: for (int count = 1; count <= 10; count++) { System.out.println("Welcome to Java"); } B: for (int count = 0; count < 10; count++) { System.out.println("Welcome to Java"); } C: for (int count = 1; count < 10; count++) { System.out.println("Welcome to Java"); } D: for (int count = 0; count <= 10; count++) { System.out.println("Welcome to Java"); }

AB

Data items you use in a call to a method are called ____.

arguments

The method ____ is the first line of a method.

declaration

A constructor that can be called without any arguments is called this.

default

A break statement in a loop causes an immediate jump to the loop condition check. T or F

false

A class' private helper method can be called from main(), which is defined in another class. T or F

false

A public member method may not call another public member method. T or F

false

If a program contains the declaration int[][] salePrice = new int[100][100]; then the statement System.out.print(salePrice[3]); outputs all the values in row 3 of the array. T or F

false

The following for loop executes 21 times. (Assume all variables are properly declared.) for (i = 1; i <= 20; i = i + 1) System.out.println(i); T or F

false

There is only one way to decompose a program into classes. T or F

false

A(n) ____ variable is known only within the boundaries of the method.

local

Which is an infinite loop?

loopCount = 1; while(loopCount < 3); { System.out.println("Hello"); }

The ____ method executes first in an application, regardless of where you physically place it within its class.

main()

A(n) ____ is a program module that contains a series of statements that carry out a task.

method


Set pelajaran terkait

Chapter 1- The Speech & Communication Process: Public Speaking

View Set

Pharmacology Chapter 1 Introduction to Drugs

View Set

PrepU - Adult Nursing III - Adolescent - Chapter 29

View Set

Anthro Final- Marriage and the Family

View Set

MULTIPLE CHOICE HOMEWORK ASSIGNMENTS CHAPTERS 1, 3, 4, 5

View Set

International Business - Chapter 5

View Set