How to use JOptionPane to input data into an array

前端 未结 2 1693
南旧
南旧 2021-01-28 02:20

how do i create an array where I want there to be 8 values in an array but the user inputs them?

this is what i have so far

                    import ja         


        
2条回答
  •  情话喂你
    2021-01-28 02:59

    you should declare your array as:

    double[] num_students = new double[8];
    

    And int FINAL MIN_STAFF = 7; should be FINAL int MIN_STAFF = 7;

    Then you may assign the value using JOptionPane by doing:

    int i=0;
    while(i<8){
       try{
           num_students[i]=Double.parseDouble(JOptionPane.showInputDialog("Enter Number:"));
           i++;
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, "Please enter valid number");
        }
    }
    

提交回复
热议问题