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

Question 1 (1 point) Which of the following java operators are defined for both

ID: 3558652 • Letter: Q

Question

Question 1 (1 point)

Which of the following java operators are defined for both int and String arguments?

Question 1 options:

the + operator

the - operator

the / operator

the * operator

the % operator

Question 2 (1 point)

Consider the following code fragment

   int big   = 10;
   int small = 20;
   big = small;

After the code executes, what are the values of the variables?

Question 2 options:

big=10 small=20

big=30 small=20

big=10 small=30

big=20 small=10

big=0 small=30

big=10 small=10

big=20 small=20

big=30 small=0

big=20 small=0

big=0 small=10

Question 3 (1 point)

Consider the following output.

  11111
  2222
  333
  44
  5

Which of the following code segments will produce this output?

Question 3 options:

for (int j = 1; j <= 5; j++) {
    for (int k = 1; k <= 5; k++)
      System.out.print(j + " ");
    System.out.println();
}

for (int j = 1; j <= 5; j++) {
    for (int k = 5; k >= j; k--)
      System.out.print(j + " ");
    System.out.println();
}

for (int j = 1; j <= 5; j++) {
    for (int k = 1; k <= j; k++)
      System.out.print(j + " ");
    System.out.println();
}

for (int j = 1; j <= 5; j++) {
    for (int k = 5; k >= 1; k--)
      System.out.print(j + " ");
    System.out.println();
}

Question 4 (1 point)

This question refers to the following code.

public int f (int n) {
    if (n < 0)
      return 2;
    else
      return f (n - 1) + f (n - 3);
}

What value is returned by the call f(3)?

Question 4 options:

8

12

10

4

6

Question 5 (1 point)

Consider the following instance variable and method.

private int[] arr;
public int f (int x) {
for (int k = arr.length - 1; k >= 0; k--)
    if (arr[k] < x) return k;
return -1;
}

Initially, suppose that arr is an arbitrary (unsorted) array and n is
an arbitrary number. Which of the following best describes the
contents of arr after the following statement has been executed?

int m = f (n);

Question 5 options:

All values in positions m+1 through arr.length-1 are less than n.

All values in positions 0 through m are less than n.

All values in positions m+1 through arr.length-1 are greater than or equal to n.

The smallest value is at position m.

The largest value that is smaller than n is at position m.

the + operator

the - operator

the / operator

the * operator

the % operator

Explanation / Answer

1) Which of the following java operators are defined for both int and String arguments?

the + operator

2) Consider the following code fragment

   int big   = 10;
   int small = 20;
   big = small;

After the code executes, what are the values of the variables?

big=20 small=20   // both hold same value i.e 20

3) Consider the following output.

11111
2222
333
44
5

Which of the following code segments will produce this output? OPTION B

for (int j = 1; j <= 5; j++) {
    for (int k = 5; k >= j; k--)
      System.out.print(j + " ");
    System.out.println();
}

4) This question refers to the following code.

public int f (int n) {
    if (n < 0)
      return 2;
    else
      return f (n - 1) + f (n - 3);
}

What value is returned by the call f(3)?

f(3) = f(2) + f(0) = 8 + 4 = 12
f(2) = f(1) + f(-1) = f(1) + 2 = 6+ 2 = 8
f(1) = f(0) + f(-2) = f(0) + 2 = 4 + 2 = 6
f(0) = f(-1) + f(-3) = 2+ 2 = 4

f(3) = 12

5) Consider the following instance variable and method.

private int[] arr;
public int f (int x) {
for (int k = arr.length - 1; k >= 0; k--)
    if (arr[k] < x) return k;
return -1;
}

Initially, suppose that arr is an arbitrary (unsorted) array and n is
an arbitrary number. Which of the following best describes the
contents of arr after the following statement has been executed?

int m = f (n);

All values in positions m+1 through arr.length-1 are greater than or equal to n..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote