该代码应该反转一个字符串,所以如果我输入“你好吗”它应该返回“你是多么嗨”并且单词以正确的顺序出现,但它们的单词也颠倒了(例如“ouy era woh ih") 有人看到我应该添加或删除什么吗?
import java.util.*;
public class ReverseString
{
public static void main(String args[])
{
String original, reverse = "";
Scanner in = new Scanner(System.in);
System.out.println("Enter a string to reverse");
original = in.nextLine();
int length = original.length();
for ( int i = length - 1 ; i >= 0 ; i-- )
reverse =reverse + original.charAt(i);
System.out.println("Reverse of entered string is "+reverse);
}
}