Я попробовал написать, как показано ниже:
Код: Выделить всё
import java.util.Arrays;
public class StringReversal_Unordered {
public static void main(String[] args) {
// TODO Auto-generated method
String str="This is a coding test, All the best!";
// Split the string into words
String[] words = str.split(" ");
// Reverse each word
for (int i = 0; i < words.length; i++) {
StringBuilder reversedWord = new StringBuilder(words[i]);
reversedWord.reverse();
words[i] = reversedWord.toString();
}
// Join the reversed words back into a string
String outputString = Arrays.toString(words);
// Remove square brackets and commas from the output string
outputString = outputString.replaceAll("\\[|\\]|,", "");
System.out.println("Input string: " + str);
System.out.println("Output string: " + outputString);
Код: Выделить всё
Input string - ***This is a coding test, All the best!***
Output string - ***sihT is a gnidoc test, All eht best!***
Подробнее здесь: https://stackoverflow.com/questions/792 ... elp-me-out