Practice Midterm coding

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

For the following code, what would be the value of str[2]?String[] str = {"abc", "def", "ghi", "jkl"};

a reference to the String object containing "ghi"

In the following code, System.out.println(num) is an example of ________.double num = 5.4;System.out.println(num);num = 0.0;

a void method

To return an array of long values from a method, which return type should be used for the method?

long[]

Instance methods do not have the ________ key word in their headers.

static

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

str1.equals(str2)

A parameter variable's scope is ________.

the method in which the parameter is declared

What will be the value of x after the following statements are executed?int x = 10;switch (x){case 10: ​x += 15; case 12: ​x -= 5; ​break; default: ​x *= 3; }

20

What is the value of charges after the following code has been executed?double charges, rate = 7.00;int time = 180;charges = time <= 119 ? rate * 2 :time / 60.0 * rate;

21.00

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

210

What will be the value of x after the following statements are executed?int x = 10;for (int y = 5; y < 20; y +=5)x += y;

4

What will be displayed after the following statements are executed?int y = 10; if (y == 10){ int x = 30; x += y; System.out.println(x); }

40

Based on the OOP NumberGuesser assignment, which of the following is a reasonable instantiation of a NumberGuesser object.

NumberGuesser g = new NumberGuesser(0, 1000);

What would be the result after the following code is executed?int[] numbers = {50, 10, 15, 20, 25, 100, 30};int value = 0;for (int i = 1; i < numbers.length; i++)value += numbers[i];

The value variable will contain the sum of all the values in the numbers array.

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

((x > 500 && x < 650) || (y != 1000))

What would be the value of bonus after the following statements are executed?int bonus, sales = 85000;char dept = 'S';if (sales > 100000)if (dept == 'R') ​bonus = 2000; else ​bonus = 1500; else if (sales > 75000)if (dept == 'R') ​bonus = 1250; else ​bonus = 1000; elsebonus = 0;

1000

What does the following statement do?double[] array1 = new double[10];

It does all of these.

Which of the following statements about this method is true: public static boolean containsTwoPairs(int[] hand) {for (int i = 0; i < hand.length; i++) {hand[i] = 0;}return true;}

It will set each element in the parameter array to zero, and it will always return true

What is the value of ans, x, and y after the following statements are executed?int ans = 0, x = 15, y = 25;if ( x >= y){ans = x + 10;x -=y;}else{ans = y + 10;y += x;}

ans = 35, x = 15, y = 40

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) {ans = x + 10;x -= y;} else {ans = y + 10;y += x;}

ans = 60, x = 0, y = 50

Consider the Circle class from the homework assignments. Imagine that you have two Circle references, c1 and c2, and that they are both initialized. Which of the following compares two circle objects to see whether or not they overlap.

c1.doesOverlap(c2)

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


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

Accounting Chapter 2 Study Guide

View Set

Blast Injuries and Trauma Resuscitation

View Set

CEU's, PDUs, CAUs, NBCOT requirements

View Set

The 12 Subdisciplines of Physical Education

View Set

Sociology of Deviance - Test #2: Chapter 5

View Set

106 Practice Test Ch Heart Failure, Dysrhythmias and Resp. Meds

View Set

COMMON REACTIONS OF SATURATED HYDROCARBONS

View Set