Skip to content

Instantly share code, notes, and snippets.

@isurum
Last active March 23, 2017 12:27
Show Gist options
  • Save isurum/6365eb2bf0502df128035c77d19c5270 to your computer and use it in GitHub Desktop.
Save isurum/6365eb2bf0502df128035c77d19c5270 to your computer and use it in GitHub Desktop.
A program displays an input dialog to prompt the user to enter an integer (line 11) and adds it to sum (line 15). Line 17 displays a confirmation dialog to let the user decide whether to continue the input. If the user clicks Yes, the loop continues; otherwise the loop exits. Finally, the program displays the result in a message dialog box (line…
package learnjava.testing;
import javax.swing.*;
/**
* Created by Isuru on 20/03/2017.
*/
public class Main {
public static void main(String args[]){
int sum = 0;
// Keep reading data until the user answers no
int option = JOptionPane.YES_OPTION;
while(option == JOptionPane.YES_OPTION){
int data = Integer.parseInt(JOptionPane.showInputDialog("Enter an int value: "));
sum += data;
option = JOptionPane.showConfirmDialog(null, "Continue?");
}
JOptionPane.showMessageDialog(null, "The sum is " + sum);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment