更新时间:2022-12-12 09:18:54
获取输入,用空格分开,并分析每个双人间。这code没有消毒的输入。
字符串输入=12.4 19.8776 23.3445
的String [] =拆分input.split();
对于(一个String:分)
{
的System.out.println(Double.parseDouble(S));
}
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 Double variables.
I have tried by assigning the first character of such string to my double variables but I haven't been able to succeed.
Any suggestions?
Thank you!
Here is what I'm trying to do:
int decision = message();
String newDimensions;
double newHeight, newWidth, newLength;
if(decision == 1){
newDimensions = JOptionPane.showInputDialog("Please enter the desired amount to be added" +
"\nto each dimension." +
"\nNOTE: First value is for Height, second for Width, third for Length" +
"\nAlso, input information has to have a blank space between each value." +
"\nEXAMPLE: 4 8 9");
newHeight = Double.parseDouble(newDimensions.charAt(0));
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));
}