import javax.swing.JOptionPane; //while loop input validation public class Ex15While { public static void main(String[] args) { final int MIN_PLAYERS = 9; //final, cannot be changed, like constant final int MAX_PLAYERS = 15; int players, teamSize, teams, leftOver; String input; input = JOptionPane.showInputDialog("Enter the number of players per team"); teamSize = Integer.parseInt(input); while (teamSize < MIN_PLAYERS || teamSize > MAX_PLAYERS) { input = JOptionPane.showInputDialog("The number must be at least " + MIN_PLAYERS + " and no more than " + MAX_PLAYERS + ".\n Enter the number of players"); teamSize = Integer.parseInt(input); } input = JOptionPane.showInputDialog("Enter the number of available players."); players = Integer.parseInt(input); while (players < 0) { input = JOptionPane.showInputDialog("Enter 0 or greater."); players = Integer.parseInt(input); } teams = players / teamSize; leftOver = players % teamSize; JOptionPane.showMessageDialog(null, "There will be "+teams+" teams with "+leftOver+ " players left over."); System.exit(0); } }