Pergunta de entrevista da empresa Pace Wisdom Solutions

Program to reverse each word in a String

Resposta da entrevista

Sigiloso

10 de jan. de 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); }