How do I convert this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

13th Dec 2020, 4:30 PM
Mayur Gowda
Mayur Gowda - avatar
9 Answers
+ 2
Mayur Gowda You can use split method like String[] arr = input.split(" "); It will give String array.
13th Dec 2020, 5:12 PM
A͢J
A͢J - avatar
+ 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]); }
13th Dec 2020, 5:22 PM
A͢J
A͢J - avatar
+ 1
Mayur Gowda Because split method accept String value as a parameter.
13th Dec 2020, 5:30 PM
A͢J
A͢J - avatar
+ 1
I Am Groot ! Right, Thanks a lot, much appreciated.
13th Dec 2020, 5:31 PM
Mayur Gowda
Mayur Gowda - avatar
0
I Am Groot ! Ok, so instead of nextLine I use .split? And what do I put inside quotes?
13th Dec 2020, 5:15 PM
Mayur Gowda
Mayur Gowda - avatar
0
I Am Groot ! Oh ok. Thanks. But why do we use the quotations?
13th Dec 2020, 5:24 PM
Mayur Gowda
Mayur Gowda - avatar
0
I Am Groot ! How do we get the output in a single line? This output is splitting into different characters and different lines.
13th Dec 2020, 5:36 PM
Mayur Gowda
Mayur Gowda - avatar
0
Mayur Gowda Don't use println then, just use print
13th Dec 2020, 5:53 PM
A͢J
A͢J - avatar
0
I Am Groot ! Ok thanks
13th Dec 2020, 5:54 PM
Mayur Gowda
Mayur Gowda - avatar