import javax.swing.*; import java.util.LinkedList; import java.util.ListIterator; public class ProblemC { public static void main(String[] args) { int M = Integer.parseInt(JOptionPane.showInputDialog("Enter M")); int N = Integer.parseInt(JOptionPane.showInputDialog("Enter N")); LinkedList L = new LinkedList(); // Fill list with players for (int i = 1; i <= M; ++i) { L.add(new Integer(i)); } ListIterator LI = L.listIterator(0); for (int j = 1; j <= M - 1; ++j) { for (int k = 1; k <= N; ++k) { if (LI.hasNext()) { LI.next(); } else { LI = L.listIterator(0); LI.next(); } } LI.remove(); } int winner = ((Integer) L.get(0)).intValue(); JOptionPane.showMessageDialog(null, "Player " + winner + " wins!"); } }