Reverse word in a string in Java | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Reverse word in a string in Java

here is my code in Java Input: Java simplified output: Simplified Java check below link: Java program to reverse words in a string using List Interface http://javasimplify.blogspot.com/2017/09/java-program-to-reverse-words-in-string.html Java program to reverse words from a string http://javasimplify.blogspot.com/2017/09/java-program-to-reverse-words-from.html

19th Sep 2017, 12:31 PM
Rushikesh Chaudhari
Rushikesh Chaudhari - avatar
1 Réponse
0
Try using Stack class like this: import java.util.*; public class Program { static Stack st = new Stack(); static void rw(String sentence) { String[] words = sentence.split(" "); for (int i = 0 ; i < words.length; i++) { st.push(words[i]); } } public static void main(String args[]) { rw("Hi there!"); while(!st.empty()){ System.out.print(st.pop() + " "); } } }
26th Apr 2018, 5:47 AM
Yashar Aliabasi
Yashar Aliabasi - avatar