import java.util.List;
import java.util.ListIterator;
import java.util.Iterator;
import java.util.ArrayList;
import javax.swing.JOptionPane;

public class MovingPlanets {
  public static void main (String args[]) {
    String names[] = {"Mercür", "Venüs", "Dünya",
      "Mars", "Jupiter", "Satürn", "Uranüs",
      "Neptün", "Pluto"};
    int namesLen = names.length;
    List planets = new ArrayList();
    for (int i=0; i < namesLen; i++) {
      planets.add (names[i]);
    }
    ListIterator lit = planets.listIterator();
    String s;
    lit.next();
    lit.next();
    s = (String)lit.next();
    lit.remove();
    lit.next();
    lit.next();
    lit.next();
    lit.add(s);
    lit.next();
    lit.previous();
    lit.previous();
    s = (String)lit.previous();
    lit.remove();
    lit.next();
    lit.next();
    lit.add(s);

    Iterator it = planets.iterator();
    String ss="";
    while (it.hasNext()) {ss+=it.next()+"\n";}
    JOptionPane.showMessageDialog(null,ss);
    System.exit(0);
  }
}
