Preview:
package com.edu4java.javatutorials;
import javax.swing.JOptionPane;

public class WhileCounterAcumulator {
	public static void main(String[] args) {
		int counter = 0;
		int accumulator = 0;
		while (counter < 5) {
			counter = counter + 1;
			accumulator = accumulator + Integer.parseInt(JOptionPane
				.showInputDialog("Enter the " + counter + "º number"));
		}
		JOptionPane.showMessageDialog(null, "The sum of the 5 numbers is " + accumulator);
	}
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter