There is a line of the form: 122.32,20.543
. How in java to cut it to get two double type double1 = 122.32
and double2 = 20.543
?
2 answers
Separate by comma and convert each substring to double.
String[] tokens = "122.32,20.543".split(","); Double double1 = Double.valueOf(tokens[0]); Double double2 = Double.valueOf(tokens[1]);
To solve, just look at the documentation for the classes String and Double.
|
and I again invented the bicycle (((
String s = "122.32,20.543"; Double d1 = Double.valueOf(s.substring(0, s.indexOf(","))); Double d2 = Double.valueOf(s.substring(s.indexOf(",")+1)); System.out.println("Число 1 = "+d1 + "\nЧисло 2 = "+ d2);
|