ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

使用确认对话框控制循环

2022-05-20 12:34:15  阅读:31  来源: 互联网

标签:option 对话框 int 确认 sum JOptionPane 循环 data OPTION


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

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有