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

后端 未结 5 699
孤街浪徒
孤街浪徒 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:57

    Get the input, split it by a whitespace and parse each Double. This code does not sanitize the input.

            String input = "12.4 19.8776 23.3445";
            String[] split = input.split(" ");
            for(String s : split)
            {
                System.out.println(Double.parseDouble(s));
            }
    

提交回复
热议问题