Question

In: Computer Science

What are the values in arrays a, b, and c after the following code executes (list...

What are the values in arrays a, b, and c after the following code executes (list all of the elements of the arrays)?

double[] a = new double[4];

double[] b = {6,4,2};

a[a.length-1] = b[b.length-1];

double[] c = b;

c[0] = -1;

b[1] = c[2];

c = a;

c[0] = -2;

a[1] = c[3];

Solutions

Expert Solution

Please find the updated code below:::

package classes10;

public class Main {
   public static void main(String[] args) {
       double[] a = new double[4];
       double[] b = {6,4,2};
       a[a.length-1] = b[b.length-1];
       double[] c = b;
       c[0] = -1;
       b[1] = c[2];
       c = a;
       c[0] = -2;
       a[1] = c[3];
      

       System.out.println("Content of array a is : ");
       for(int i=0;i<a.length;i++){
           System.out.print(a[i]+" ");
       }
      
       System.out.println(" Content of array b is : ");
       for(int i=0;i<b.length;i++){
           System.out.print(b[i]+" ");
       }
      
       System.out.println(" Content of array c is : ");
       for(int i=0;i<c.length;i++){
           System.out.print(c[i]+" ");
       }
   }
}

output:


Related Solutions

After the code executes (in C++), what will the linked list 8->4->3->7->5 look like? (8 is...
After the code executes (in C++), what will the linked list 8->4->3->7->5 look like? (8 is the head) 1a) Node* newNode = new Node(26); newNode->next = head->next; head = newNode; 1b) Node* curNode = head; for(int i=0; i<2; i++) curNode = curNode->next; Node* temp = curNode->next; curNode->next = curNode->next ->next; delete temp; temp = nullptr;
What will be the values of A, B, C and D after execution of the following...
What will be the values of A, B, C and D after execution of the following procedure using the “Scores” dataset? Note: Consider fractions up to 2 decimal places e.g. 10 / 3 = 3.33, 20 / 3 = 6.67 Step 1. Arrange all cards in a single pile called Pile 1 Step 2. Maintain five variables A, B, C, D, percentage and initialize them to 0 Step 3. If Pile 1 is empty then stop the iteration Step 4....
What are the values of a, b, c, d, and e after the following statements? int...
What are the values of a, b, c, d, and e after the following statements? int a = 5, b = 2, c = 8, d = 7, e = 4; int x = c - b + a; a = a + x - d; b = c * d - x; c = e + a / 2; d = x - c * a; e = x + d - c;
Counting SortShow the B and C arrays after Counting Sort finishes on the array A [19,...
Counting SortShow the B and C arrays after Counting Sort finishes on the array A [19, 6, 10, 7, 16, 17, 13, 14, 12, 9] if the input range is 0-19.
Write a MIPS program that executes the statement: s = (a + b) – (c +...
Write a MIPS program that executes the statement: s = (a + b) – (c + 101), where a, b, and c are user provided integer inputs, and s is computed and printed as an output. Answer the following: a. Suppose the user enters a = 5, b = 10, and c = -30, what is the expected value of s? b. Which instruction in your program computed the value of s and which register is used? c. What is...
Code in C++ Assign negativeCntr with the number of negative values in the linked list. #include...
Code in C++ Assign negativeCntr with the number of negative values in the linked list. #include <iostream> #include <cstdlib> using namespace std; class IntNode { public: IntNode(int dataInit = 0, IntNode* nextLoc = nullptr); void InsertAfter(IntNode* nodePtr); IntNode* GetNext(); int GetDataVal(); private: int dataVal; IntNode* nextNodePtr; }; // Constructor IntNode::IntNode(int dataInit, IntNode* nextLoc) { this->dataVal = dataInit; this->nextNodePtr = nextLoc; } /* Insert node after this node. * Before: this -- next * After: this -- node -- next */...
What is displayed to the screen when the following code executes? Counter c1 = new Counter();...
What is displayed to the screen when the following code executes? Counter c1 = new Counter(); Counter c2 = new Counter(); Counter c3 = new Counter(); Counter[] A = {c1, c2}; JAVA A[0].clickButton(); Counter[] B = new Counter[2]; for(int i = 0; i < A.length; i++) B[i] = A[i]; B[0] = c3; System.out.println("A[0] is " + A[0].getCount()); System.out.println("B[0] is " + B[0].getCount());
C++ Code Required to Show The constructor of parent class executes before child class
C++ Code Required to Show The constructor of parent class executes before child class
hat are the values of the elements in the vector named names_1 after the following code...
hat are the values of the elements in the vector named names_1 after the following code is executed? vector<string> names_1 { "Mike", "Ben", "Joel", "Anne" }; vector<string> names_2 { "Judy", "Samantha", "Kelly" }; names_1.insert(names_1.end(), "Mary"); names_1.erase(names_1.begin());         names_1.insert(names_1.begin() + 2, ++names_2.begin(), names_2.end()); names_1.swap(names_2); names_1.erase(++names_1.begin()); names_1.insert(names_1.begin(), ++names_2.begin(), names_2.begin() + 2); a. Joel, Judy, Samantha b. Judy, Mary, Joel, Mary c. Joel, Anne, Judy, Samantha d. Joel, Judy, Kelly 1.5 points    QUESTION 12 What are the values of the key/value pairs in...
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a,...
2. Translate the following C/Java code to MIPS assembly code. Assume that the values of a, i, and j are in registers $s0, $t0, and $t1, respectively. Assume that register $s2 holds the base address of the array A (add comments to your MIPS code). j = 0; for(i=0 ; i<a ; i++) A[i]=i+j++;
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT