问题
I am given the string "23 45" I need to get 2 variables (int a) with the value 23 and (int b) with value 45
回答1:
if your input String name is ' in ' , then we will have :
String in = "23 45";
String s[] = in.split(" ");
int out[] = new int[s.length];
for(int i = 0 ; i < s.length ; i++)
out[i] = Integer.parseInt(s[i]);
output is now in out array
来源:https://stackoverflow.com/questions/39882367/java-how-to-split-a-string-with-numbers-separated-by-spaces-into-variables