Question: import java.util.LinkedList ; import java.util.ListIterator ; /** Based on a Big Java problem You have to write a static method that removes every other element

import java.util.LinkedList ;
import java.util.ListIterator ;
/**
   Based on a Big Java problem

   You have to write a static method that removes every other
   element from a linked list.  
   Expected output:

[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
[Monday, Wednesday, Friday]
[Wednesday]
[]
 */

public class DownSizeTester
{
    public static void main(String[] args)
    {
        LinkedList list = new LinkedList() ;
        list.add("Sunday") ;
        list.add("Monday") ;
        list.add("Tuesday") ;
        list.add("Wednesday") ;
        list.add("Thursday") ;
        list.add("Friday") ;
        list.add("Saturday") ;
        System.out.println(list) ;
        downsize(list) ;
        System.out.println(list) ;
        downsize(list) ;
        System.out.println(list) ;
        downsize(list) ;
        System.out.println(list) ;
        System.out.println("Expected:[Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]");
        System.out.println("[Monday, Wednesday, Friday]");
        System.out.println("[Wednesday]");
        System.out.println("[]");
    }
    /**
       Removes the first, third, fifth, ... elements from a list (i.e. the elements at the odd indices).
       @param list a linked list of String elements
     */
    public static void downsize(LinkedList list)
    {
        //-----------Start below here. To do: approximate lines of code = 6
        // Remove the first, third, fifth, ... elements from list
        for(int i=0;
                i = list.remove(i);

                )
        //-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
    }

Please recheck your code. DownSizeTester.java:54: error: illegal start of statement } 1

Fix my code so it works and gives the expected output

Please recheck your code. DownSizeTester.java:54: error: illegal start of statement } 1 error

Step by Step Solution

3.35 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilLinkedList import javautilListIterator Based on a Big Java problem You have to write ... View full answer

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!