Below is a method intended to modify the input array by doubling each element and a main method that calls it. What does this code print out? If the method does not do what is intended, what needs to be modified?

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter14: Files And Streams
Section: Chapter Questions
Problem 17RQ
icon
Related questions
Question

JAVA:

Below is a method intended to modify the input array by doubling each element and a main method that calls it. What does this code print out? If the method does not do what is intended, what needs to be modified?

public static void doubleArray (int[] a){
int[] newA = new int[a.length];
for (int i = 0; i < a.length; i++){
newA[i] = 2*a[i];
}
a = newA;
} // doubleArray
public static void main(String[] args){
int[] a = new int[]{1,2,3,4,5,6};
doubleArray (a);
for(int i = 0; i < a.length; i++){
System.out.print(a[i]);
}
}
Transcribed Image Text:public static void doubleArray (int[] a){ int[] newA = new int[a.length]; for (int i = 0; i < a.length; i++){ newA[i] = 2*a[i]; } a = newA; } // doubleArray public static void main(String[] args){ int[] a = new int[]{1,2,3,4,5,6}; doubleArray (a); for(int i = 0; i < a.length; i++){ System.out.print(a[i]); } }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,