Take different values from a String and convert them to Double Values

后端 未结 5 696
孤街浪徒
孤街浪徒 2021-01-27 09:10

In my code, I\'m asking the user to input three different values divided by a blank space. Then, those three different values I would like to assign them to three different

5条回答
  •  抹茶落季
    2021-01-27 09:37

    Try something like this:

    newDimensions = JOptionPane.showInputDialog(...
    
    newDimensions = newDimensions.trim();
    
    String arr[] = newDimensions.split(" ");
    
    double darr[] = new double[arr.length];
    
    for(int i=0;i

    There are still some defensive issues that can be taken. Doing a trim on your parse double is kind of critical.

提交回复
热议问题