Question

In: Computer Science

QUESTION 5 What is printed? int[] aArray = {1, 2, 3, 4}; int[] bArray = {5,...

QUESTION 5

  1. What is printed?

    int[] aArray = {1, 2, 3, 4};
    int[] bArray = {5, 6, 7, 8};
    bArray = aArray;
    System.out.print(bArray[2]);

1 points   

QUESTION 6

  1. What is printed?

    public static void main(String[] args)
     {
     int[] aArray = { 1, 2, 3, 4 };
     System.out.print(aArray[2]);
     int i = aMeth(aArray);
     System.out.print(i + "" + aArray[2]);
    }
    public static int aMeth(int[] iArray)
     {
     for (int i = 0; i < iArray.length; i++)
     {
     iArray[i]++;
     }
     int[] bArray = { 5, 6, 7, 8 };
     iArray = bArray;
     return iArray[2];
    }
     
     

1 points   

QUESTION 7

  1. Assuming that array myList is properly declared and initialized with values, what best describes the following code snippet?

    double max = myList[0];

    for (int i = 1; i < myList.length; i++) {

    if (myList[i] > max) max = myList[i];

    }

    sets max to the largest index in the array

    sets max to the index of the largest value in the array

    sets max to the largest positive value in the array

    sets max to the largest value in the array

1 points   

QUESTION 8

  1. Given the following two arrays, which of the following will copy the values from sourceArray into targetArray?

    int[] sourceArray = {2, 3, 1, 5, 10};

    int[] targetArray = new int[sourceArray.length];

    sourceArray = targetArray;

    targetArray = sourceArray;

    targetArray[] = sourceArray[];

    sourceArray.copyInto(targetArray, 0, sourceArray.length);;

    None of the above

QUESTION 1

  1. An array is an object

    True

    False

1 points   

QUESTION 2

  1. To add a new element on to the end of an array myArray,

    assign a new value to element myArray[myArray.length]

    use the myArray.add method

    use the myArray.resize method followed by the myArray.add

    new elements can't be added on to the end of an array

1 points   

QUESTION 3

  1. Assume myArray is a valid and instantiated array of int values. Also assume the user is asked for an int value arIndx, and enters -1.

    myArray[arIndx] = 3;

    will

    set the [-1] element of myArray to 3, even though this memory isn't in myArray's memory

    cause a compiler error

    cause a runtime exception

    renumber myArray's elements to be from -1 to myArray.length-2   

1 points   

QUESTION 4

  1. Note: Multiple Answer

    Which of the following will add 1 to each element of an appropriately declared, created and initialized int[] iVals?

    int i = iVals.length - 1;
    while (i >= 0)
    {
     iVals[i]++;
     i--;
    }
    for (int i: iVals)
    {
     i = i + 1;
    }
    for (int i: iVals)
    {
     iVals[i]++;
    }
     
    for (int i = 0; i < iVals.length; i++)
    {
     iVals[i] += 1

QUESTION 9

  1. In order to perform a binary search on an array, which of the following must be true (select all that apply)?

    The array must be ordered

    The array must contain integers

    The array must have an even number of elements

    The array must have an odd number of elements

1 points   

QUESTION 10

  1. Command line arguments are made available to main() via an array of _______.

1 points   

QUESTION 11

  1. The first action performed in a binary search is

    Determine the largest value in the array

    Determine the smallest value in the array

    Determine the mid-point of the array

    Determine if the array is sorted

1 points   

QUESTION 12

  1. If an array contains unordered values, searching for a particular value

    is accomplished with a linear search

    is accomplished with the bipolar search

    can't be done in Java

    requires multiple parallel processing threads

1 points   

QUESTION 13

  1. What best describes the processing of the following method?

    public static int[] mystery(int[] list) {

    int[] result = new int[list.length];

    for (int i = 0, j = result.length - 1;

           i < list.length; i++, j--) {

        result[j] = list[i];

    }

    return result;

    }

    Returns an array with the values from list sorted in ascending order

    Returns an array with the values from list sorted in descending order

    Returns an array with the values from list decremented by 1

    Returns an array with the values from list reversed

1 points   

QUESTION 14

  1. The first action performed in Selection Sort is

    convert all values to integers

    find the largest value in the array

    locate the midpoint of the array

    find the smallest value in the array

1 points   

QUESTION 15

  1. When Selection Sort is run against an array the end result is

    the values in the array are reordered smallest to largest

    the array is unchanged because the sorted values are placed in a different array

    none of the other answers are correct

    the values in the array are reordered largest to smallest

Solutions

Expert Solution

1. Answer: True, they are object that can be dynamically created and assigned variable values

2. Answer: new elements can't be added on to the end of an array, as the size of the array is fixed. We can make arrays dynamic using arraylist

3. Answer: cause a runtime exception as ArrayIndexOutOfBoundException

4. Answer: a and d

int i = iVals.length - 1;
while (i >= 0)
{
 iVals[i]++;
 i--;
}

And

for (int i = 0; i < iVals.length; i++)
{
 iVals[i] += 1

}

5 Answer: 3, as the value of first array is assigned to second array

6. Answer: 3, 7 and 4 are the values obtained as output

7. Answer: Sets max to the largest value in the array

8. Answer: targetArray = sourceArray;

9. Answer: to perform binary search The array must be ordered and The array must contains integers

10.Answer: Array of strings represented mostly as args

11.Answer: Determine the mid-point of the array

12. Answer: is accomplished with a linear search

13. Answer: Returns an array with the values from list sorted in descending order

14 Answer: find the smallest value in the array

15. Answer: the values in the array are reordered smallest to largest


Related Solutions

Calories BMI 1 2 2 4 3 5 4 4 5 5 What is the R-squared...
Calories BMI 1 2 2 4 3 5 4 4 5 5 What is the R-squared for this table and how do we interpret that?
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int...
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int n, int k)             if (n <= 0) return 0;             else if (A[n] < k) return (1+ 2*BBOX(n-1,k+1));             else return BBOX(n-1,k-2);             Find BBOX(8, 5)
4. (a) Suppose that τσ=(1 5 2 3)(4) and στ=(1 2 4 5)(3) in S5. If...
4. (a) Suppose that τσ=(1 5 2 3)(4) and στ=(1 2 4 5)(3) in S5. If σ1 = 2, find σ and τ. (b) In Sn, show that σ = τ if and only if σ(τ)^(−1) = ε. ε is the identity permutation. Must be written as a proof. (c) Let σ=(1 2 3) and τ=(1 2) in S3. Show that S3={ε,σ,σ^2,τ,τσ,τ(σ)^2} and that σ^3=ε=τ^2 and στ=τ(σ)^2, then fill out the multiplication table for S3.
coffee tea juice 3 4 5 5 4 3 4 4 4 5 1 2 4...
coffee tea juice 3 4 5 5 4 3 4 4 4 5 1 2 4 2 2 Do a One-way ANOVA by hand (at least once in your life!) …Is there a difference in attention for those who drink coffee, tea, or juice during an 8 a.m. class? Utilize the five steps of hypothesis testing to analyze the following data (p<.01). Attention Ratings (1=no attention- 5=full attention)
Find the distances: A) Between ?1=〈2+2?,−1+?,−3?〉and ?2=〈4,−5−3?,1+4?〉 . B) Between the planes 2?−?+5?=0 and 2?−?+5?=5 ....
Find the distances: A) Between ?1=〈2+2?,−1+?,−3?〉and ?2=〈4,−5−3?,1+4?〉 . B) Between the planes 2?−?+5?=0 and 2?−?+5?=5 . C) From the point (1,2,3) to the line ?=〈−?,4−?,1+4?〉 .
5 + (3 * 4)^2 - 2 = 147             (5 + 3) * 4^2 -...
5 + (3 * 4)^2 - 2 = 147             (5 + 3) * 4^2 - 2 = 126             (5 + 3 )* (4^2 – 2) = 112             5 + (3 * 4^2) - 2 = 51 Which is the correct answer to using the "order of precedence" and why?
X 1 3 5 3 4 4 Y 2 5 4 3 4 6 A: Plot...
X 1 3 5 3 4 4 Y 2 5 4 3 4 6 A: Plot the date B: find the line of best fit C: determine ŷ AT x=3 D: Find r and r^2 E: explain r and r^2
Raysut Cement Company: Strengths: 1- 2- 3- 4- 5- Weaknesses : 1- 2- 3- 4- 5-...
Raysut Cement Company: Strengths: 1- 2- 3- 4- 5- Weaknesses : 1- 2- 3- 4- 5- Opportunities : 1- 2- 3- 4- 5- Threats: 1- 2- 3- 4- 5-
COLLAPSE Overall Rating: 1 2 3 4 5 1 2 3 4 5 " Service Positioning...
COLLAPSE Overall Rating: 1 2 3 4 5 1 2 3 4 5 " Service Positioning versus Product Process " Please respond to the following: Examine the roles of Enterprise Resource Planning (ERP) and Customer Relationship Management (CRM) in business. Determine how each system can play a critical role in managing value chains. How does LaRosa’s Pizzeria use this technology in order to improve the supply chain and value chain operations? Determine the ways this technology has helped to deliver...
needed asap !!! 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand  ...
needed asap !!! 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below: Line Number: 5 Error description: Missing semicolon...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT