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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education