Traditional Culture Encyclopedia - Photography and portraiture - Java problem: extract numbers separated by spaces from strings

Java problem: extract numbers separated by spaces from strings

If you say "extract numbers separated by spaces from a string"

The following method is correct: "Take out the data separated by spaces"

string str = " 16 5 12 136 ";

string[]s = str . split(" ");

//You can convert the obtained value into int.

for(int I = 0; I<s. Length; i++) {

system . out . println(s[I]);

}

If you follow the example you gave: "If the string" 16 5 12 136 "is output as: 165 12 136".

Then the following should be correct.

string str = " 16 5 12 136 ";

string[]s = str . split(" ");

//You can convert the obtained value into int.

for(int I = 0; I<s. Length; i++) {

system . out . print(s[I]);

} so you can output the results you want.