Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

int x = 4; if (x < 0) { x *= -1; } What does the code snippet do? 2.) Given the

ID: 3824898 • Letter: I

Question

int x = 4;

if (x < 0) {

x *= -1;

}

What does the code snippet do?

2.) Given the following function prototype:

public static void Display(int[] ary)

Select the correct choice below.

3.) Large complex problems are best solved by __________ .

4.)

Select the choice that initializes all elements in the array to -1.

a.) int[][] ary = new int[N][N];

for (int i = 0; i < N; i++)

{

ary[i][j] = -1;

}

b.) int[][] ary = new int[N][N];

for (int i = 0; i < N; i++) {

for (int j = 0; j < N; j++) {

ary[i][j] = -1;

}}

c.) int[][] ary = new int[N][N];

for (int i = 0; i < N; i++) {

for (int j = 0; j < N; j++) {

ary[i] = -1;

}}

a. the code snippet creates the absolute value of x

Explanation / Answer

Question 1:

Answer: b. the code snippet cannot work since x is greater than 0.

x values is 4 which is greater then zero so it skips the if condition

Question 2:

Answer:

The argument passed to the function is an integer array.

Question 3:

Answer:

dividing the problem into functions

yes convert the repeated code part in function and call when ever in use reduces the large code problem

Question 4:

Answer:

b.) int[][] ary = new int[N][N];

for (int i = 0; i < N; i++) {

for (int j = 0; j < N; j++) {

ary[i][j] = -1;

}}

c.

The argument passed to the function is an integer array.