-5

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

  • What does "splitting a string into variables" mean? Can you provide an example? – Scott Hunter Oct 05 '16 at 19:44
  • This is almost exactly the same except the separating character is `|` instead of space: http://stackoverflow.com/questions/14414582/java-split-string-to-array – SunKnight0 Oct 05 '16 at 19:47

1 Answers1

5

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

Mohsen_Fatemi
  • 2,183
  • 2
  • 16
  • 25