Sum the integers in input.
String s; // current string in input int n; // current integer int sum; // variable used as accumulator sum = 0; s = JOptionPane.showInputDialog("Input an integer"); while (s != null) { n = Integer.parseInt(s); sum = sum + n; s = JOptionPane.showInputDialog("Input an integer"); } System.out.println("sum = " + sum);