
A Program To Reverse Words In String in Java :-
For Example :-
Input:- Computer Software
Output :- Software Computer

Here is a code that reverses the words from the string.
import java.util.*;
class ReverseWords{
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter String: ");
String st=input.nextLine();
StringBuffer buffer=new StringBuffer();
String str[]=st.split(" ");
for(int i=str.length-1;i>=0;i--){
buffer.append(str[i]);
buffer.append(" ");
}
System.out.println("Input: "+st);
System.out.println("Output: "+buffer.toString());
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.