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 as the last element of heightList.
Ex: If the input is then the output is:
List contains:
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 mainString args
Scanner scnr new ScannerSystemin;
LinkedList heightList new LinkedList;
ListIterator heightIterator;
int i;
int nextIndex;
int previousIndex;
for i ; i ; i
heightList.addscnrnextInt;
Your code goes here
previousIndex heightIterator.previousIndex;
nextIndex heightIterator.nextIndex;
System.out.printList contains:";
heightIterator heightList.listIterator;
while heightIteratorhasNext
System.out.print heightIterator.next;
System.out.println;
if nextIndex heightList.size
System.out.printlnheightIterator is at the end of the list.";
else
System.out.printlnheightIterator is between heightList.getpreviousIndex and heightList.getnextIndex;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
