Hi All,
I am very green with Java programming and I am in a class in which I have to answer some questions. The one question that will not compile correctly is:
Assume that an ArrayList of integers named a has been declared and initialized. Write a single statement that assigns a new value to the first element of the ArrayList. The new value should be equal to twice the value stored in the last element of the ArrayList.
This is the code that is provided to me:
import java.util.*; public class CTest { public static void main(String[] args) { int j = 2; ArrayList<Integer> a = new ArrayList<Integer>(Arrays.asList(343,43,65,34,564)); //<My Answer goes here> } }
Here's my answer to the question:
a[0] = 2 * a[a.length-1];
Here's the compile errors I'm getting:
Errors:
CTest.java:8: error: cannot find symbol
a.get[0] = 2 * a[a.length-1];
^
symbol: variable get
location: variable a of type ArrayList<Integer>
CTest.java:8: error: cannot find symbol
a.get[0] = 2 * a[a.length-1];
^
symbol: variable length
location: variable a of type ArrayList<Integer>
CTest.java:8: error: array required, but ArrayList<Integer> found
a.get[0] = 2 * a[a.length-1];
^
3 errors
I'm not sure why this is not working? Any help would be appreciated, because I really do not know much about this.
Thanks,
T