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 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...
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++;
Need this C++ code to be modified to work in C, still using 2d arrays... #include...
Need this C++ code to be modified to work in C, still using 2d arrays... #include <iostream> #include <stdlib.h> #include <time.h> using namespace std; //Implementation of main function int main() { srand(time(NULL)); //Declaration of output,result,i,j,k ,figure as integer type and //assign flog with 0 int output[5][5], result[5], i, j, k, figure = 0; //Display statement cout << "The classic BINGO cards contains 25 squares arranged in five vertical" << endl; cout << "columns and five side to side rows. Each...
Convert the following pieces of code in just a single line of code. In all cases, A and B are arrays of size 5 x 5.
Convert the following pieces of code in just a single line of code. In all cases, A and B are arrays of size 5 x 5. Important: The expression "single line of code" implies a single command or equality. In other words, the code: X=A+1; X=X+B; is considered to be TWO lines. (a) (4%) for i=1:5, for j=1:5 A(i,j)=B(i,j)+1; end end _________________________________ (b) (4%) for i=1:3 for j=2:4 A(i,j)=B(i,j); end end _________________________ (c) (5%) for i=1:3 for j=2:4 A(i,j)=B(i+2,j+1); end...
Given the list values = [], write code that fills the list with each set of...
Given the list values = [], write code that fills the list with each set of numbers below. Note: use loops if it is necessary 1 2 3 4 5 6 7 8 9 10 0 2 4 6 8 10 12 14 16 18 20 1 4 9 16 25 36 49 64 81 100 0 0 0 0 0 0 0 0 0 0 1 4 9 16 9 7 4 9 11 0 1 0 1 0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT