Question: JAVA HELP! Four integers are read from input and inserted into heightList. Complete the following tasks: Assign heightIterator with heightList's ListIterator object. Move heightIterator to

JAVA HELP! Four integers are read from input and inserted into heightList. Complete the following tasks:
Assign heightIterator with heightList's ListIterator object.
Move heightIterator to the end of heightList.
Use heightIterator add value -1 as the last element of heightList.
Ex: If the input is 21273815, then the output is:
List contains: 21273815-1
heightIterator is at the end of the list.
CODE:
import java.util.Scanner;
import java.util.LinkedList;
import java.util.ListIterator;
public class HeightsList {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
LinkedList heightList = new LinkedList();
ListIterator heightIterator;
int i;
int nextIndex;
int previousIndex;
for (i =0; i <4; ++i){
heightList.add(scnr.nextInt());
}
/* Your code goes here */
previousIndex = heightIterator.previousIndex();
nextIndex = heightIterator.nextIndex();
System.out.print("List contains:");
heightIterator = heightList.listIterator();
while (heightIterator.hasNext()){
System.out.print(""+ heightIterator.next());
}
System.out.println();
if (nextIndex == heightList.size()){
System.out.println("heightIterator is at the end of the list.");
}
else {
System.out.println("heightIterator is between "+ heightList.get(previousIndex)+" and "+ heightList.get(nextIndex)+".");
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!