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

1. Which of these expressions evaluates to 5.5?(1 point) I. (double)(11 / 2) II.

ID: 3810102 • Letter: 1

Question

1.

Which of these expressions evaluates to 5.5?(1 point)

I. (double)(11 / 2)
II. 11 / (double)2
III. 11 / 2.0

Question 1 options:

2.

How many columns are in the array? (1 point)

char[][] array1 = new char[15][10];

Question 2 options:

3.

If String str = "The There Here", then what is the value of str.indexOf("he");?(1 point)

Question 3 options:

4.

What is the value of vals[4][1]?(1 point)

double[][] vals = {1.1, 1.3, 1.5},
                               {3.1, 3.3, 3.5},
                               {5.1, 5.3, 5.5},
                               {7.1, 7.3, 7.5}

Question 4 options:

5.

Consider the method total below.(1 point)

public static int total (int result, int a, int b)
{            if (a == 0)
              {
                       if (b == 0)
                             {
                                    return result * 2;
                             }
                            return result / 2;
    }
              else
             {
                        return result * 3;
            }
}The assignment statementx = total (5, 0, 1);must result in

Question 5 options:

6.

Which of the following statements creates alpha, a two-dimensional array of 10 rows and 5 columns, wherein each component is of the type int?(1 point)

int[][] alpha = new int[10][5];

int[][] alpha;
     alpha = new int[10][];
     for (int i = 0; i < 10; i++)
          alpha[i] = new int[5];

Question 6 options:

7.

Consider the method total below.(1 point)

public static int total (int result, int a, int b)
{
            if (a == 0)
              {
                        if (b == 0)
                             {
                                    return result * 2;
                             }
                            return result / 2;    
             }
              else
             {
                        return result * 3;
            }
}
            
The assignment statement
x = total (5, 0, 0);
must result in

Question 7 options:

8.

Consider the following definitions.

public boolean state (int[] list, int value)
{
            int counter;
            boolean flag = false;
            for (counter = 0; counter < list.length; counter++)
               {
                        flag = (list[counter] != value);
            }
            return flag;
}

Under which of the following conditions must the method above return true ? (1 point)  

Question 8 options:

Under all conditions.

Under the condition that value == list[list.length - 1].

Under the condition that value != list[list.length - 1].

Under the condition that value != list[i] for all i such that 0 <= i < list.length.

Under no conditions.

9.

What is the output of the program shown below? (1 point)

public class SomeClass
{
            private int x, y;

            public SomeClass (int xValue, int yValue)
               {
                        x = xValue;
                        y = yValue;
            }                       
            public void m1()
              {
                        x = 30;
                        System.out.print((y + 1) + " ");
            }
            public void m2()
              {
                        m1();
                        System.out.print(x + " ");
            }
}
public class Tester
{
            public static void main (String[] args)
               {
                        int x = 10;
                        int y = 20;
                        SomeClass z = new SomeClass(y, x);
                        z.m2();
                        z.m1();
            }
}

Question 9 options:

10.

What is output by the following code? (1 point)

public class Swapper
{
            private int a, b;
            public Swapper(int aValue, int bValue)
              {
                        a = aValue;
                        b = bValue;
            }
            public void swap ()
              {
                        a = b;
                        b = a;
            }
            public void print ()
              {
                        System.out.println("a = " + a + ", and b = " + b);
              }
}
public class Tester
{
            public static void main(String[] args)
               {
                        Swapper swapObj = new Swapper(10, 20);
                        swapObj.swap();
                        swapObj.print();
              }
}

Question 10 options:

11.

If the value of f(x, y, z) is always an integer, which of the following conditions ensures that the loop below terminates? (1 point)

            while (f(x, y, z) < 100)
              {
                        
              }

Question 11 options:

12.

The following program segment is intended to sum a[0] through a[n-1], where n = a.length:
            sum = 0;
               i = 0;
            n = a.length;
            while (i != n)  
              {
                        i++;
                        sum += a[i];
            }

In order for this segment to perform as intended, which of the following modifications, if any, should be made?(1 point)

Question 12 options:

1) I only 2) II only 3) III only 4) II and III only 5) I, II, and III

Explanation / Answer

Answers:

1. 4. II and III only

2. 3. 10

3. 2. 1

4. 4. There is no such value

5. 4. x being assigned the value 2

6. 3. Both i and ii

7. 5)    x being assigned the value 10

8. 4) Under the condition that value != list[i] for all i such that 0 <= i < list.length

9. 2) 21 30 21

10. 4) a = 20, and b = 20

11. 2) The value of f(x, y, z) is increased during each iteration.

12. 5) i++; should be interchanged with sum += a[i];