使用确认对话框控制循环
作者:互联网
import java.util.*;
import javax.swing.*;
class Main {
public static void main(String[] args){
int sum = 0;
//Keep reading data until the user answer No
int option = JOptionPane.YES_OPTION;
while(option == JOptionPane.YES_OPTION){
//Read the next data
String dataString = JOptionPane.showInputDialog("Enter an int value: ");
int data = Integer.parseInt(dataString);
sum += data;
option = JOptionPane.showConfirmDialog(null,"Continue?");
}
JOptionPane.showMessageDialog(null, "The sum is " + sum);
}
}
标签:option,对话框,int,确认,sum,JOptionPane,循环,data,OPTION 来源: https://www.cnblogs.com/doudou-20123/p/16291907.html