TEST_3_MCQ_STUDYGUIDE(Rest of 41 questions), Test3_MCQ_StudyGuide (1st 40 questions!)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

64) What is output? public static void swap(int val1, int val2) { int temp; temp = val1; val1 = val2; val2 = temp;} public static void main(String[] args) { int x; int y; x = 10; y = 20; swap(x, y); System.out.println(x + ", " + y);} a. 10, 20 b. 20, 20 c. 10, 10 d. 20, 10

a. 10, 20

33) Which statement correctly calls calcArea() with two int arguments? a. calcArea(4, 12); b. public void calcArea(int w, int h); c. calcArea(int w, int h); d. calcArea( );

a. calcArea(4, 12);

48) While performing main(), what is the value of tripleValue at XXX? public static int tripleTheValue(int val) { int tripleValue; tripleValue = val * 3; return tripleValue; } public static void main(String args[]) { int result; result = tripleTheValue(4); XXX} a. not defined b. 4 c. 3 d. 12

a. not defined

41) Which is the best stub for a method that calculates an item's tax? a. public static double ComputeTax(double itemPrice) { double TAXRATE = 0.0675; return itemPrice * TAXRATE; } b. public static double ComputeTax(double itemPrice) { double tax; return tax; } c. public static double ComputeTax(double itemPrice) { System.out.println("FIXME: Calculate tax"); return 0.0; } d. public static double ComputeTax(double itemPrice) { double tax = 0.0; }

a. public static double ComputeTax(double itemPrice) { double TAXRATE = 0.0675; return itemPrice * TAXRATE; }

19) What code for XXX, YYY correctly swaps a and b? Choices are written as XXX / YYY. XXX; a = b; YYY; b = tmp; a. tmp = a / (nothing) b. tmp = a / tmp = b c. tmp = b / (nothing) d. (nothing) / tmp = a

a. tmp = a / (nothing)

38) How many items are returned from printValues()? public static void printValues(int a, int b){. . .} a. 0 b. 1 c. 2 d. 3

a.) 0

7) Which XXX / YYY declare an array having MAX_SIZE elements and initializes all elements with -1? final int MAX_SIZE = 4; int[] myNumbers = new int[XXX]; int i; for (i = 0; i < YYY; ++i) { myNumbers[i] = -1; } a. MAX_SIZE / MAX_SIZE b. MAX_SIZE / MAX_SIZE - 1 c. MAX_SIZE - 1 / MAX_SIZE d. MAX_SIZE - 1 / MAX_SIZE - 1

a.) MAX_SIZE / MAX_SIZE

20) Given an array with values 5, 10, 15, 20, 25, what are the fewest number of swaps needed to reverse the list? a.2 b. 3 c. 4 d. 5

a.2

68) What is copiedNums' length after the code segment? int[] originalNums = {1,2,3,4,5}; int[] copiedNums; copy(originalNums, 3); public static int[] copy(int[] nums, int changeAmt) { int[] modifiedNums = new int[nums.length * changeAmt]; int index; for(index = 0; index < nums.length; ++index){ modifiedNums[index] = nums[index]; } return modifiedNums; } a. null b. 0 c. 5 d. 15

a.null

1) Given array scorePerQuiz has 10 elements. Which assigns the 7th elementwith the value 8? a. scorePerQuiz = 8; b. scorePerQuiz[6] = 8; c. scorePerQuiz[7] = 8; d. scorePerQuiz[8] = 7;

b) scorePerQuiz[6] = 8;

13) The numNegatives variable counts the number of negative values in the array userVals. What should numNegatives be initialized to? int[] userVals = new int[20]; int i; int numNegatives; numNegatives = XXX; for (i = 0; i < 20; ++i) { if (userValues[i] < 0) { numNegatives = numNegatives + 1; } } a. No initialization needed b. 0 c. -1 d. userVals[0]

b. 0

46) For the given program, how many print statements will execute? public static void printShippingCharge(double weight) { if((weight > 0.0) && (weight <= 10.0)){ System.out.println(weight * 0.75); } else if((weight > 10.0) && (weight <= 15.0)){ System.out.println(weight * 0.85); } else if((weight > 15.0) && (weight <= 20.0)) { System.out.println(weight * 0.95); } } public static void main(String args[]) { printShippingCharge(18); printShippingCharge(6); printShippingCharge(25); } a. 1 b. 2 c. 3 d. 9

b. 2

21) Given that integer array x has elements 4, 7, 3, 0, 8, what are the elements after the loop? int i; for (i = 0; i < 4; ++i) { x[i] = x[i + 1]; } a. 4, 4, 7, 3, 0 b. 7, 3, 0, 8, 8 c. 7, 3, 0, 8, 4 d. Error: Invalid access

b. 7, 3, 0, 8, 8

49) Which is true regarding how methods work? a. After a method returns, its local variables keep their values, which serve as their initial values the next time the method is called b. A method's local variables are discarded upon a method's return; each new call creates new local variables in memory c. A return address indicates the value returned by the method d. If a method returns a variable, the method stores the variable's value until the method is called again

b. A method's local variables are discarded upon a method's return; each new call creates new local variables in memory

69) The frequency() method is supposed to return the number of occurrences of target within the array.Identify the location of any errors. public static int[] frequency(int[] nums, int target){ int index; int count = 0; for(index = 0; index < nums.length; ++index) { if(nums[index] == target) { ++count; } } return count;} a. The code has no errors b. Only the method signature has an error c. Only the method body has errors d. Both the method signature and body have errors

b. Only the method signature has an error

73) The frequency() method is supposed to return the number of occurrences of target within the array.Identify the location of any errors. public static int frequency(int[] nums, int target){ int index; int count = 0; for(index = 0; index < nums.length; ++index) { if(nums[index] == target) { ++count; } } return count;} a. The code has no errors b. Only the method signature has an error c. Only the method body has errors d. Both the method signature and body have errors

b. Only the method signature has an error

42) How does using findMax() improve the code? public static int findMax(int val1, int val2) { int max; if(val1 > val2) { max = val1; } else { max = val2; } return max; } public static void main(String args[]){ int max1; int max2; int max3; max1 = findMax(15, 7); max2 = findMax(100, 101); max3 = findMax(20, 30); } a. Using findMax() makes main() run faster b. Using findMax() decreases redundant code c. Using findMax() reduces the number of variables d. Using findMax() does not improve the code

b. Using findMax() decreases redundant code

57) What is the output? public static int changeValue(int x) { int y; x = x * 2; y = x + 1; return y; } public static void main(String args[]) { int a; a = 5; System.out.print("a = " + a + ", result = " + changeValue(a)); } a. a = 5, result = 6 b. a = 5, result = 11 c. a = 10, result = 11 d. Error: Cannot assign parameter x

b. a = 5, result = 11

31) Which method name isnotvalid? a. calcAverage() b. calc Average() c. _calcAvg() d. calc_average()

b. calc Average()

36) Which is a valid method call for findMax()? public static double findMax(double x, double y){. . .} a. double val = findMax(); b. double val = findMax(4.2, 20.7); c. double val = findMax(19.6); d. int val = findMax(7.9, 20.3);

b. double val = findMax(4.2, 20.7);

9) Which assigns the array's last element with 99? int[] myVector = new int[15]; a. myVector[0] = 99; b. myVector[14] = 99; c. myVector[15] = 99; d. myVector[16] = 99;

b. myVector[14] = 99;

56) What is the output? public static void swapValues(int x, int y) { int tmp; tmp = x; x = y; y = tmp;} public static void main(String args[]) { int p = 4, q = 3; swapValues(p, q); System.out.print("p = " + p + ", q = " + q);} a. p = 3, q = 3 b. p = 4, q = 3 c. p = 3, q = 4 d. Error: Argument names must match parameter names

b. p = 4, q = 3

63) What is the content of array ages after calling shift()? public static void shift(int[] nums) { int i; for(i = 0; i < nums.length-1; ++i) { nums[i] = nums[i+1]; }} public static void main(String[] args) { int[] ages = {16, 19, 24, 17}; shift(ages);} a. {16, 19, 24, 17} b. {19, 24, 17, 17} c. (19, 24, 17, 16) d. {16, 16, 19, 24}

b. {19, 24, 17, 17}

35) How many items are returned from calcAverage()? public static int calcAverage(int a, int b, int c){. . .} a. 0 b. 1 c. 2 d. 3

b.1

3) What is the ending value of the element at index 0? int[] numbers = new int[10];numbers[0] = 35;numbers[1] = 37;numbers[1] = numbers[0] + 4; a. 0 b. 35 c. 37 d. 39

b.35

2) What is the index of the last element? int[] numList = new int[50]; a. 0 b. 49 c. 50 d. Unknown, because the array has not been initialized.

b.49

34) Which list correctly defines three parameters of type int, double, and String for createRecord()?public static void createRecord(. . .){}; a. (int num, int cost, int name) b. (num, cost, name) c. (int num, double cost, String name) d. (17, 12.34, "Janet")

c. (int num, double cost, String name)

55) What is output? public static void changeRainfall(double [] dailyRain) { dailyRain[0] = 0.1;} public static void main(String args[]) { double [] rainValues = new double[2]; rainValues[0] = 2.9; rainValues[1] = 1.3; changeRainfall(rainValues); System.out.println(rainValues[0]);} a. 2.9 b. 1.3 c. 0.1 d. an array reference

c. 0.1

62) What is output? public static void curveGrades(int curve, int[] grades) { curve = curve + 5; grades[0] = grades[0] + curve;} public static void main(String[] args) { int[] myGrades = {72, 67, 85}; int amt; amt = 10; curveGrades(amt, myGrades); System.out.println(amt + ", " + myGrades[0]);} a. 10, 72 b. 15, 87 c. 10, 87 d. 10, 82

c. 10, 87

54) Which is true about arrays and methods? a. Arrays cannot be passed to methods b. Passing an array to a method creates a copy of the array within the method c. An array is passed to a method as a reference d. A programmer must make a copy of an array before passing the array to a method

c. An array is passed to a method as a reference

16) Two arrays, itemsNames and itemsPrices, are used to store a list of item names and their corresponding prices. Which is true? a. Using two arrays saves memory versus using one array. b. Both arrays should be of the same data type. c. Both arrays should be declared to have the same number of elements. d. The item names should appear in both arrays.

c. Both arrays should be declared to have the same number of elements.

72) What is the likely purpose of someMethod() based on the signature? int someMethod(int[] nums) a. Create a new array b. Modify the array contents c. Calculate a value based on the array contents d. Make a copy of the array

c. Calculate a value based on the array contents

61) What is the output for the call displayTime(15, 24, 65)? public static void displayTime(int hr, int min, int sec) { if(hr < 1 || hr > 12) { System.out.print("Error: hour "); hr = 1; } if(min < 1 || min > 59) { System.out.print("Error: minute "); min = 1; } if(sec < 1 || sec > 59) { System.out.print("Error: second "); sec = 1; } System.out.println(hr + ":" + min + ":" + sec);} a. 15:24:65 b. 1:24:1 c. Error: hour Error: second 1:24:1 d. Error: second 1:24:1

c. Error: hour Error: second 1:24:1

43) A programmer develops code by repeating short sessions of writing, compiling, and testing until the project is finished. This is an example of _____. a. Pair programming b. Modular development c. Incremental development d. Parallel programming

c. Incremental development

51) Which line has an error? 1 public static int computeSumOfSquares(int num1, int num2) {2 int sum;3 sum = (num1 * num1) + (num2 * num2);4 return;5 } a. Line 1 b. Line 3 c. Line 4 d. None of the lines contains an error

c. Line 4

52) calcSum() was copied and modified to create calcProduct(). Which line in calcProduct() contains an error? 1 public static int calcSum(int a, int b) {2 int s; 3 s = a + b;4 return s;5 }6 public static int calcProduct(int a, int b) {7 int p; 8 p = a * b;9 return s;10 } a. Line 7 b. Line 8 c. Line 9 d. There are no errors

c. Line 9

70) What is the likely purpose of someMethod() based on the signature? void someMethod(int[] nums, int value) a. Create a new array b. Change all array elements tovalue c. Return the number of timesvalueoccurs in the array d. Make a copy of the array

c. Return the number of timesvalueoccurs in the array

17) Given two arrays, which code will output all the arrays' elements, in the order key, item followed by a newline? int[] keysList = new int[SIZE_LIST]; int[] itemsList = new int[SIZE_LIST]; a. System.out.println(keysList[SIZE_LIST - 1] + ", " + itemsList[SIZE_LIST - 1]); b. System.out.println(keysList[SIZE_LIST] + ", " + itemsList[SIZE_LIST]); c. for (i = 0; i < SIZE_LIST - 1; ++i) { System.out.println(keysList[i] + ", " + itemsList[i]); } d. for (i = 0; i < SIZE_LIST; ++i) { System.out.println(keysList[i] + ", " + itemsList[i]); }

c. for (i = 0; i < SIZE_LIST - 1; ++i) { System.out.println(keysList[i] + ", " + itemsList[i]); }

29) Which regular loop corresponds to this enhanced for loop? char[] vowels = {'a', 'e', 'i', 'o', 'u'}; for (char item: vowels) { System.out.println(item); } a. for (int i = 0; i < item; ++i) { System.out.println(vowels[i]);} b. for (int i = 0; i < item.length; ++i) { System.out.println(vowels[i]);} c. for (int i = 0; i < vowels.length; ++i) { System.out.println(vowels[i]);} d. for (int i = 0; i < vowels.length; ++i) { System.out.println(item[i]);}

c. for (int i = 0; i < vowels.length; ++i) { System.out.println(vowels[i]);}

28) Which XXX and YYY correctly complete the code to find the maximum score? Choices are in the form XXX / YYY. int[] scores = {43, 24, 58, 92, 60, 72}; int maxScore; maxScore = scores[0]; for (XXX) { if (num > maxScore) { YYY; } } a. int scores: num / maxScore = num b. scores != 0 / num = maxScore c. int num: scores / maxScore = num d. num < scores / num = maxScore

c. int num: scores/maxScore = num

25) Which statement declares a two-dimensional integer array called myArray with 3 rows and 4 columns? a. int myArray[3, 4]; b. int[] myArray = new int[7]; c. int[][] myArray = new int[3][4]; d. int[] myArray = new int[4][3];

c. int[][] myArray = new int[3][4];

44) For the following method, which is a valid function call? Assume maxValue is an integer. public static int findMax(int x, int y) { if (x > y){ return x; } else { return y; } } a. maxValue = findMax(15 25); b. maxValue = findMax(); c. maxValue = findMax(15, findMax(35, 25)); d. findMax = maxValue(15, 25);

c. maxValue = findMax(15, findMax(35, 25));

59) What is the scope of odometer defined on line 7? 1 public class SimpleCar { 2 private int odometer; 3 public void driveForward(int miles) { 4 odometer = odometer + miles; 5 } 6 public void changeOdometer(int miles) { 7 int odometer; 8 odometer = miles; 9 } 10 } a. method driveForward() b. odometer is not defined c. method changeOdometer() d. all of class SimpleCar

c. method changeOdometer()

14) Which best describes what is output? Assume v is a large array of ints. int i; int s; s = v[0]; for (i = 0; i < N_SIZE; ++i) { if (s > v[i]) { s = v[i]; } } System.out.println(s); a. first value in v b. max value in v c. min value in v d. last value in v

c. min value in v

8) Which assigns the array's first element with 99? int[] myVector = new int[4]; a. myVector[] = 99; b. myVector[-1] = 99; c. myVector[0] = 99; d. myVector[1] = 99;

c. myVector[0] = 99;

6) Which is an invalid access for the array? int[] numsList = new int[5]; int x = 3; a. numsList[x-3] b. numsList[0] c. numsList[x+2] d. numsList[(2*x) - x]

c. numsList[x+2]

32) In calcArea(), width and height are _____ public static void calcArea(int width, int height){}; a. arguments b. statements c. parameters d. method names

c. parameters

45) Which XXX calculates the area using the CalcSquare() method? The formula to calculate the area of a circle ispi * . public static double calcSquare(double x) { return x*x; } public static double calcArea(double r) { final double PI_VAL = 3.14159265; XXX; } public static void main(String args[]) { System.out.println(calcArea(5.0)); } a. PI_VAL * r * r; b. PI_VAL * calcSquare(r); c. return PI_VAL * calcSquare(r); d. return PI_VAL * calcSquare(r) * calcSquare(r);

c. return PI_VAL * calcSquare(r);

15) Given two arrays, studentNames that maintains a list of studentnames, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX / YYY. String[] studentNames = new String[NUM_STUDENTS]; int[] studentScores = new int[NUM_STUDENTS]; int i; for (i = 0; i < NUM_STUDENTS; ++i) { if (XXX > 80) { System.out.print(YYY + " "); } } a. studentNames[i] / studentNames[i] b. studentNames[i] / studentScores[i] c. studentScores[i] / studentNames[i] d. studentScores[i] / studentScores[i]

c. studentScores[i] / studentNames[i]

27) Which XXX and YYY will find the minimum value of all the elements in the array? Choices are in the form XXX / YYY. int[][] userVals = new int[NUM_ROWS][NUM_COLS]; minVal = userVals[0][0]; for (i = 0; i < NUM_ROWS; ++i) { for (j = 0; j < NUM_COLS; ++j) { if (XXX) { YYY; } } } a. userVals[i] < minVal / minVal = userVals[i] b. userVals[j] < minVal / minVal = userVals[j] c. userVals[i][j] < minVal / minVal = userVals[i][j] d. userVals[i][j] > minVal / minVal = userVals[i][j]

c. userVals[i][j] < minVal / minVal = userVals[i][j]

18) Given x = 4 and y = 8, what are the ending values of x and y? x = y; y = x; x = y; a. x = 4, y = 4 b. x = 4, y = 8 c. x = 8, y = 4 d. x = 8, y = 8

c. x = 8, y = 4

53) What is output? public static void changeRainfall(double [] dailyRain){ dailyRain[0] = 0.1;} public static void main(String args[]){ double [] rainValues = new double[2]; rainValues[0] = 2.9; rainValues[1] = 1.3; changeRainfall(rainValues); System.out.println(rainValues);} a. 2.9 b. 1.3 c. 0.1 d. an array reference

c.01

66) What is copiedNums' length after the code segment? int[] originalNums = {1,2,3,4,5};int[] copiedNums;copiedNums = copy(originalNums, 2); public static int[] copy(int[] nums, int changeAmt) { int[] modifiedNums = new int[nums.length * changeAmt]; int index; for(index = 0; index < nums.length; ++index){ modifiedNums[index] = nums[index]; } return modifiedNums;} a. 0 b. 5 c. 7 d. 10

d. 10

47) What is the output? public static void printFeverCheck (double temp) { final double NORMAL_TEMP = 98.6; final double CUTOFF_TEMP = 95; double degreesOfFever; if (temp > NORMAL_TEMP) { degreesOfFever = temp - NORMAL_TEMP; System.out.print("You have " + degreesOfFever + " degrees of fever."); } else if (temp < CUTOFF_TEMP) { degreesOfFever = CUTOFF_TEMP - temp; System.out.print("Your temperature is " + degreesOfFever + " below 95."; } } public static void main(String args[]) { double bodyTemperature; bodyTemperature = 96.0; System.out.print("Checking for fever..."); printFeverCheck(bodyTemperature); } a. Nothing is output b. Checking for fever...Your temperature is 2.6 below 95. c. Checking for fever...Your temperature is 2.6 below 95. d. Checking for fever...

d. Checking for fever...

24) Given two integer arrays, largerArray with 4 elements, and smallerArray with 3 elements. What is the result after this code executes? for (i = 0; i < 4; ++i) { largerArray[i] = smallerArray[i]; } a. All the elements of largerArray will get copied to smallerArray. b. Some of the elements of largerArray will get copied to smallerArray. c. All of the elements of smallerArray will get copied to largerArray. d. Error: The two arrays are not the same size.

d. Error: The two arrays are not the same size.

60) What is the output for the call displayTime(2, 24, 65)? public static void displayTime(int hr, int min, int sec) { if(hr < 1 || hr > 12) { System.out.print("Error: hour "); hr = 1; } if(min < 1 || min > 59) { System.out.print("Error: minute "); min = 1; } if(sec < 1 || sec > 59) { System.out.print("Error: second "); sec = 1; } System.out.println(hr + ":" + min + ":" + sec);} a. 2:24:65 b. 2:24:1 c. Error: second 2:24:65 d. Error: second 2:24:1

d. Error: second 2:24:1

37) Given: public static void printName(String first, String last){ System.out.println(last + ", " + first); } What is printed with the following method call? printName("Bob", "Henderson"); a. Bob, Henderson b. Henderson,Bob c. Bob Henderson d. Henderson, Bob

d. Henderson, Bob

40) Select thetruestatement. a. A benefit of methods is to increase redundant code b. A key reason for including methods is to make main() run faster c. Method stubs can not be compiled d. Method stubs are temporary placeholders used during development

d. Method stubs are temporary placeholders used during development

22) Given that integer array x has elements 5, 10, 15, 20, what is the output? int i; for (i = 0; i < 4; ++i) { System.out.print(x[i] + x[i + 1]); } a. 10, 15, 20, 5 b. 15, 25, 35, 25 c. 15, 25, 35, 20 d. Out of range access

d. Out of range access

12) The following program generates an error. Why? final int NUM_ELEMENTS = 5; int[] userVals = new int[NUM_ELEMENTS]; int i; userVals[0] = 1; userVals[1] = 7; userVals[2] = 4; for (i = 0; i <= userVals.length; ++i) { System.out.println(userVals[i]); } a. Variable i is never initialized. b. The array userVals has 5 elements, but only 3 have values assigned. c. The integer NUM_ELEMENTS is declared as a constant d. The for loop tries to access an index that is out of the array's valid range.

d. The for loop tries to access an index that is out of the array's valid range.

58) What is the scope of odometer defined on line 2 1 public class SimpleCar { 2 private int odometer; 3 public void driveForward(int miles) { 4 odometer = odometer + miles; 5 }6 public void changeOdometer(int miles) {7 int odometer;8 odometer = miles;9 } 10} a. method driveForward() b. odometer is not defined c. method changeOdometer() d. all of class SimpleCar

d. all of class SimpleCar

23) Given two integer arrays prevValues and newValues. Which code copies the array prevValues into newValues? The size of both arrays is NUM_ELEMENTS. a. newValues = prevValues; b. newValues[] = prevValues[]; c. newValues[NUM_ELEMENTS] = prevValues[NUM_ELEMENTS]; d. for (i = 0; i < NUM_ELEMENTS; ++i) { newValues[i] = prevValues[i];}

d. for (i = 0; i < NUM_ELEMENTS; ++i) { newValues[i] = prevValues[i];}

71) Which XXX in firstHalf() that returns a new array with a copy of the first half of all elements in array nums. public static int[] firstHalf(int[] nums) { int index; int size = nums.length / 2; XXX for(index = 0; index < size; ++index) { halfNums[index] = nums[index]; } return halfNums;} a. int[ ] halfNums; b. int halfNums = new int[size]; c. int[ ] halfNums = new int[nums.length]; d. int[ ] halfNums = new int[size];

d. int[ ] halfNums = new int[size];

11) Which XXX and YYY correctly output the smallest values? Array userVals contains 100 elements that are integers (which may be positive or negative). Choices are in the form XXX / YYY. // Determine smallest (min) value int minVal; XXX for (i = 0; i < 100; ++i) { if (YYY) { minVal = userVals[i]; } } System.out.println("Min: " + minVal); a. minVal = 0; / userVal > minVal b. minVal = 0; / userVal < minVal c. minVal = userVals[0]; / userVals[i] > minVal d. minVal = userVals[0]; / userVals[i] < minVal

d. minVal = userVals[0]; / userVals[i] < minVal

30) The enhanced for loop _____ a. reduces the number of iterations necessary to visit all elements of an array b. can be used to replace any regular for loop while yielding less code c. creates a copy of an existing array and iterates through the copy's elements d. prevents incorrectly accessing elements outside of an array's range

d. prevents incorrectly accessing elements outside of an array's range

39) The following program generates an error. Why? public static void printSum(int num1, int num2) { System.out.print(num1 + num2); } public static void main(String args[]) { int y; y = printSum(4, 5); return 0; } a. printSum() is missing a "return;" statement. b. The values 4 and 5 cannot be passed directly to printSum() c. main() has a return statement that returns the value 0 d. printSum() has void return type, so cannot be assigned to a variable

d. printSum() has void return type, so cannot be assigned to a variable

Which statement is true? void swap(int age, int [] grades) { a. the value of age is stored in the heap b. the reference to grades is stored in the heap c. the elements in grades can not be modified within the method d. the value of grades[2] is stored in the heap

d. the value of grades[2] is stored in the heap

50) Which is true regarding tripleTheValue()? public static int tripleTheValue(int val) { int tripleValue; tripleValue = val * 3;} a. val should be returned b. tripleValue should be defined as double c. there are no errors d. tripleValue should be returned

d. tripleValue should be returned

10) What are the ending contents of the array? Choices show elements in index order 0, 1, 2. int[] yearsList = new int[3]; yearsList[0] = 5; yearsList[1] = yearsList[0]; yearsList[0] = 10; yearsList[2] = yearsList[1]; a. 5, 5, 5 b. 5, 10, 10 c. 10, 10, 10 d. 10, 5, 5

d.) 10, 5, 5

5) How many elements does the array declaration create? int[] scores = new int[10]; scores[0] = 25; scores[1] = 22; scores[2] = 18; scores[3] = 28; a. 0 b. 4 c. 9 d. 10

d.10

4) What is the ending value of the element at index 1? int[] numbers = new int[10]; numbers[0] = 35;numbers[1] = 37;numbers[1] = numbers[0] + 4; a. 0 b. 35 c. 37 d. 39

d.39

26) How many elements are in the array? int[][] userVals = new int[2][4]; a. 2 b. 4 c. 6 d. 8

d.8

67) What is copiedNums' length after the code segment? int[] originalNums = {1, 2, 3, 4}; int[] copiedNums = {0, 0, 0}; copiedNums = copy(originalNums, 2); public static int[] copy(int[] nums, int changeAmt) { int[] modifiedNums = new int[nums.length * changeAmt]; int index; for(index = 0; index < nums.length; ++index){ modifiedNums[index] = nums[index]; } return modifiedNums; } a. 3 b. 4 c. 6 d. 8

d.8


Ensembles d'études connexes

CompTIA A+ 220-901 598 questions

View Set

General Principles of Physiology

View Set

Algebra terms and writing expressions and equations

View Set