0

How to process String words letter by letter?

Sololearn has added a challenge in which it asks to print the words which the user inputs, backwards? For example:- Input :- sick Output :- kcis Input:- name Output:- eman

21st May 2020, 12:30 PM
Yash Dwivedi
Yash Dwivedi - avatar
4 Antworten
0
You can use the string methods charAt(index) or toCharArray().
21st May 2020, 12:43 PM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar
+ 1
What if you turn the string into a array, and then use a loop to print all array elements, starting from the last element and continue until reach the first one. //just a thought. Idk anything about Java.
21st May 2020, 12:41 PM
🍇 Alex Tușinean 💜
🍇 Alex Tușinean 💜 - avatar
0
Manu_1-9-8-5 if you don't mind can you write a sample code or so I'm a beginner, I don't know where to put that method☹️
21st May 2020, 12:54 PM
Yash Dwivedi
Yash Dwivedi - avatar
0
Alright, with this you can reverse the complete String. for (int i = s.length() - 1; i > -1; i--) { System.out.print(s.charAt(i)); } Consider that you have to print words in the same order, but backwards. Try it and if you cannot get further ask here again.
21st May 2020, 2:15 PM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar