Menu

String Reversal by word by word

import java.util.*;
class StringintoWords{
public static void main(String args[]){

Scanner sc= new Scanner(System.in);
String str= sc.nextLine();

String words[] = str.split(" ");
String reversal="";



for(int i=0;i<words.length;i++)
{
String word= words[i];


String rev_word="";
for(int j=word.length()-1; j>0;j--)
{
rev_word=rev_word+word.charAt(j);
}

reversal=reversal+rev_word+" ";
}

System.out.println(reversal);
}}