COP2258- Test 2 (quizzes)
Given the declarationint[][] 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]);
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 count; int num = 2; for (count = 1; count < 4; count++) { num = num + 3; System.out.print(num + " "); } System.out.println();
5 8 11
When a variable ceases to exist at the end of a method, programmers say the variable ____.
Goes out of scope
A(n) ____ causes a value to be sent from a called method back to the calling method.
return statement
Which of the following is a valid call statement to the method given above?
secret(5, 4.8);
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 num = 14; while (num <= 32) num = num + 10; System.out.println( num );
34
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
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
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
The method ____ is the first line of a method.
Declaration
A break statement in a loop causes an immediate jump to the loop condition check.
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.
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);
False
A(n) ____ variable is known only within the boundaries of the method.
Local
A(n) ____ is a program module that contains a series of statements that carry out a task.
Method
public static double secret(int first, double second) { double temp; if (second > first) temp = first * second; else temp = first - second; return temp; }
Secret
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.
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
A method body provides information about how other methods can interact with it
True
An application's main() method must have a void return type.
True
In Java, a two-dimensional array is actually an array of references to one-dimensional arrays.
True
The statementint[][] scaleFactor ={{5, 2, 8, -2},{6, 0, 1, 7}}; is a valid statement for declaring and initializing the scaleFactor array.
True
The values in an array are accessed by an index, whereas the values in a class are accessed by name.
True
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()