Back to Examples
package edu.iuk.Addition;

//import JOptionPane library
import javax.swing.JOptionPane;

public class addition {

  public static void main(String[] args) {

    //Jacob Morris
    //Declare Variables
    int sum = 0;
    int counter = 0;
    String number;

    //Do this until the user enters “*”
    while(counter == 0)
    {

      number = (JOptionPane.showInputDialog(“Please enter a number. If all numbers have been entered, enter *”));

      if(number.equals(“*”)){

        //User entered “*”
        counter += 1;

      } else{

        //Add the number to the sum
        sum += Integer.parseInt(number);
      }     }
  JOptionPane.showMessageDialog(null, “The total of all numbers entered is ” + sum);

  }
}
Back to Examples

Startup Discount
Small Business?
Contact us for an Enormous Discount!