employer cover photo
employer logo
employer logo

Pace Wisdom Solutions

Is this your company?

Pace Wisdom Solutions interview question

Program to reverse each word in a String

Interview Answer

Anonymous

Jan 10, 2023

public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the String: "); String str = sc.nextLine(); String[] words = str.split(" "); String reversedString = ""; for (int i = 0; i < words.length; i++) { String word = words[i]; String reverseWord = ""; for (int j = word.length()-1; j >= 0; j--) { reverseWord = reverseWord + word.charAt(j); } reversedString = reversedString + reverseWord + " "; } System.out.println("Reversed String :"); System.out.println(reversedString); }