Programming Final - Practice Exam Questions

Ace your homework & exams now with Quizwiz!

Which is an invalid access for the array? int[] numsList = new int[5];int x = 3;

numsList[x+2]

What is the output? int columns;int rows;for (rows = 0; rows < 2; ++rows) { for (columns = 0; columns < 3; ++columns) {System.out.print("x");}System.out.println();}

xxx xxx

Consider a method that is provided a numerical grade (0 - 100) as a parameter and returns a corresponding letter grade (A - F). Which collection of values would be the most appropriate for testing the method?

-1, 0, 50, 65, 73, 92, 100, and 1000

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

0.1

What is the output? j and k are ints. for (j = 0; j < 2; ++j) {for (k = 0; k < 4; ++k) { if (k == 2) {break;}System.out.print("" + j + k + " ");}}

00 01 10 11

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

10, 5, 5

What is the index of the last element? int[] numList = new int[50];

49

What is the output, if the input is 3 2 1 0? x = scnr.nextInt();while (x > 0) {System.out.print(2 * x + " ");}

6 6 6 6 6 ... (infinite loop)

How many elements are in the array? int[][] userVals = new int[2][4];

8

Two arrays, itemsNames and itemsPrices, are used to store a list of item names and their corresponding prices. Which is true?

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

Which is an essential feature of a while loop having the following form?while (LoopExpression) {LoopBody}

The LoopExpression should be affected by the LoopBody

Which statement correctly calls calcArea() with two int arguments?

calcArea(4, 12);

Which XXX causes every character in string inputWord to be output? for (XXX) {System.out.println(inputWord.charAt(i)); }

i = 0; i < inputWord.length(); ++i

Mandy designs a Student object that includes a name, address and gpa. This is an example of ___.

data encapsulation

Which is a valid method call for findMax()? public static double findMax(double x, double y){. . .}

double val = findMax(4.2, 20.7);

Which assigns the array's first element with 99? int[] myVector = new int[4];

myVector[0] = 99;

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

p = 4, q = 3

In calcArea(), width and height are _____public static void calcArea(int width, int height){};

parameters

Which method is called? p = processData(9.5, 2.3);

public static int processData (double num, double x){...};

How many items are returned from calcAverage()? public static int calcAverage(int a, int b, int c){. . .}

1

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

10

What is the output, if the input is 3 2 4 5? All variables are ints. num = scnr.nextInt();for (i = 0; i < num; ++i) {curr = scnr.nextInt();System.out.print(curr);}

245

What is the output? public static void main(String[] args) {for (int i = 0; i < 3; ++i) {System.out.print(i);}System.out.print(i);}

Error: The variable i is not declared in the right scope

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

Using findMax() decreases redundant code

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}

not defined


Related study sets

IC Intro: Unit 1 - What's your name?

View Set

AP US History Exploration (Test questions)

View Set

hormonal regulation of bone tissue *test 2*

View Set

Humanism, the Renaissance, and the Protestant Reformation

View Set

Chapter 25: Structure and Function of the Cardiovascular System

View Set

SUCCESS! In Clinical Laboratory Science - Clinical Chemistry: Instrumentation and Analytical Principles (1-35)

View Set

13.B & 13.C Fractures/Hip Fractures

View Set

MANA 3318 Chapter 16: Organizational Culture

View Set