sider an array of integers. We need to copy that array into an ArrayList, in reversed order. To do this, you need to complete the method, named copyRevers meter to this method: the original array of integers. The method returns the new ArrayList, with the contents reversed in order from the original array. example, consider the following array of integers: 9, 27, 81] n you call the copyReverse method with this array, the return value should be a new ArrayList containing the same elements, but in reversed order: , 27, 9, 3] rayops.java 1 2 import java.util.ArrayList; 3 public class Arrayops 4 { 6789 This method goes through the array of integers identified by the only parameter, creating a new ArrayList from the array, but in reverse order. @param theArray, an array of integers

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 18RQ
icon
Related questions
Question

Why am I getting an error? What do I change to make it work?

Consider an array of integers. We need to copy that array into an ArrayList, in reversed order. To do this, you need to complete the method, named copyReverse, in the class named Arrayops.java. There is only one
parameter to this method: the original array of integers. The method returns the new ArrayList, with the contents reversed in order from the original array.
For example, consider the following array of integers:
[3, 9, 27, 81]
When you call the copyReverse method with this array, the return value should be a new ArrayList containing the same elements, but in reversed order:
[81, 27, 9, 3]
ArrayOps.java
1 import java.util.ArrayList;
3 public class Array0ps
{
/**
This method goes through the array of integers identified by
the only parameter, creating a new ArrayList from the array,
but in reverse order.
31
32 }
@param theArray, an array of integers
@return reversedArr, the new ArrayList of Integers
*/
public static ArrayList copyReverse (int[] anArray)
{
// declare new ArrayList
}
ArrayList<Integer> revArrayList = new ArrayList<Integer>();
// loop though anArray, in reverse,
// storing each element in the ArrayList
for (int i = anArray.length - 1; i >= 0; i--) {
revArrayList.add (anArray(i));
}
return revArrayList;
Transcribed Image Text:Consider an array of integers. We need to copy that array into an ArrayList, in reversed order. To do this, you need to complete the method, named copyReverse, in the class named Arrayops.java. There is only one parameter to this method: the original array of integers. The method returns the new ArrayList, with the contents reversed in order from the original array. For example, consider the following array of integers: [3, 9, 27, 81] When you call the copyReverse method with this array, the return value should be a new ArrayList containing the same elements, but in reversed order: [81, 27, 9, 3] ArrayOps.java 1 import java.util.ArrayList; 3 public class Array0ps { /** This method goes through the array of integers identified by the only parameter, creating a new ArrayList from the array, but in reverse order. 31 32 } @param theArray, an array of integers @return reversedArr, the new ArrayList of Integers */ public static ArrayList copyReverse (int[] anArray) { // declare new ArrayList } ArrayList<Integer> revArrayList = new ArrayList<Integer>(); // loop though anArray, in reverse, // storing each element in the ArrayList for (int i = anArray.length - 1; i >= 0; i--) { revArrayList.add (anArray(i)); } return revArrayList;
Array0ps.java:24: error: cannot find symbol
revArrayList.add (anArray(i));
symbol: method anArray (int)
location: class Array0ps
1 error
Score
0
Transcribed Image Text:Array0ps.java:24: error: cannot find symbol revArrayList.add (anArray(i)); symbol: method anArray (int) location: class Array0ps 1 error Score 0
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Arrays
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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT