Computer Science, asked by karanrajpurohit869, 9 months ago

Wap to reverse each word in the sentence and print the reversed string

Answers

Answered by hoangmustang
2

Answer:

package newPack;

import java.util.*;

public class reverseString {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);//create Scanner object

String s = input.nextLine();//read the input from the user

String[]a=s.split(" ");//divide the string into string array

for(int i = 0; i < a.length; i++) {//read each element in the array

for(int j = a[i].length()-1; j >= 0; j--) {//reverse  

 System.out.print(a[i].charAt(j));

}

System.out.print(" ");

}

}

}

Explanation:

This is written in java, hope it helpful!

Similar questions