0
How do I convert this?
How do I convert the input string into String array instead of a char array?A user taught me this earlier but me being stupid as is, deleted the question by mistake twice. https://code.sololearn.com/c5Vc0a6V4iGQ/?ref=app
9 Answers
+ 2
Mayur Gowda
You can use split method like
String[] arr = input.split(" ");
It will give String array.
+ 1
Mayur Gowda No nextLine is use to take input. You have to split the input string.
String a1 = input.nextLine();
String [] arr = a1.split(" ");
for(int i= arr.length-1;i>=0;i--){
System.out.println(arr[i]);
}
+ 1
Mayur Gowda Because split method accept String value as a parameter.
+ 1
I Am Groot ! Right, Thanks a lot, much appreciated.
0
I Am Groot ! Ok, so instead of nextLine I use .split? And what do I put inside quotes?
0
I Am Groot ! Oh ok. Thanks. But why do we use the quotations?
0
I Am Groot ! How do we get the output in a single line? This output is splitting into different characters and different lines.
0
Mayur Gowda
Don't use println then, just use print
0
I Am Groot ! Ok thanks