Given that an ArrayList named a whose elements are of type int has been declared assign the value -1?
-
I've been having trouble figuring out these erros. Any help is greatly appreciated!! :) 1) Given that an ArrayList named a whose elements are of type int has been declared, assign the value -1 to the last element in a . My answer (Unexpected identifiers: get): a.get(a.size() - 1, -1); 2) Assume that an ArrayList of Integer s named a that contains exactly five elements has been declared and initialized. In addition, an int variable j has also been declared and initialized to a value somewhere between 0 and 3 . Write a single statement that assigns a new value to element of the ArrrayList indexed by j . This new value should be equal to twice the value stored in the next element of the ArrayList (i.e. the element after the element indexed by j . My answer (error: Unexpected identifiers: length) : a.set(0, 2*(a.get(a.length - 1))); 3)The superclass Student contains: a constructor that accepts a String corresponding to the name of the school the student attends a toString method that returns 'student at X' where X is the name of the school the student attends. Write a class definition for the subclass HighSchoolStudent containing: a constructor accepting a String which is used as a parameter to the superclass constructor a toString method that returns 'high school student at X'. This method must use the toString method of its superclass. My answer (error said expected but did not find a (default-access) constructor accepting a java.lang.String parameter.) : class HighSchoolStudent extends Student{ public HighSchoolStudent(String X) { super(X); } public String toString() { return "high school student at" + super.toString(); } }
-
Answer:
1) The get method doesn't set anything, it only returns the value at the given index. You're looking for the set method. The set method takes in an int index and an object to set at that index. So you'd want a.set(a.size()-1, -1); 2) You want a new element at index j, that has the value of two times the element at index j+1. So you're looking for: a.set(j, 2*(a.get(j+1)));
hello at Yahoo! Answers Visit the source
Other answers
1) The get method doesn't set anything, it only returns the value at the given index. You're looking for the set method. The set method takes in an int index and an object to set at that index. So you'd want a.set(a.size()-1, -1); 2) You want a new element at index j, that has the value of two times the element at index j+1. So you're looking for: a.set(j, 2*(a.get(j+1)));
Eric
Related Q & A:
- Unix tools: what if a file is named minus something?Best solution by Super User
- How do you create a Two-Dimensional ArrayList?Best solution by Stack Overflow
- What's a good amp for alpine type R?Best solution by Yahoo! Answers
- What is a pimpin Myspace profile layout type?Best solution by Yahoo! Answers
- Is there a website where I can type in a sentence and see if the sentence is correct or not?Best solution by textranch.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.