While statement, counter and accumulator variables

PHOTO EMBED

Mon Nov 30 2020 13:06:36 GMT+0000 (UTC)

Saved by @rainxx #java

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);
	}
}
content_copyCOPY

http://www.edu4java.com/en/java/while-statement-counter-accumulator-variable.html