我是 Java 新手,我有这个反向代码。我的问题是如何使用 BufferedReader 以便在我写希腊字母(如 ξηφαιπασς)时它也会返回反向的希腊字母。目前我得到的只是一些正方形。我第一次在这里写一个问题,所以请原谅我的任何错误。
导入java.io.*;// 对于 I/O
///////////////////////////////////// //////////////////
类 StackX
{
private int maxSize;
私有字符 [] 堆栈数组;
私有int顶部;
//------------------------------------------------ ------------- public StackX(int max) // 构造函数
{
maxSize = max;
stackArray = new char[maxSize];
顶部 = -1;
}
//------------------------------------------------ --------------public char pop() // take item from top of stack { return stackArray[top--]; } //-------------------------------------------------------------> public boolean isEmpty() // true if stack is empty { return (top == -1); } //------------------------------------------------------------- } // end class StackX //////////////////////////////////////////////////////////////// class Reverser { private String input; // input string private String output; // output string > public Reverser(String in) // constructor { input = in; } //-------------------------------------------------------------> public String doRev() // reverse the string { int stackSize = input.length(); // get max stack size StackX theStack = new StackX(stackSize); // make stack for(int j=0; j<input.length(); j++) { char ch = input.charAt(j); // get a char from input theStack.push(ch); // push it } output = ""; while( !theStack.isEmpty() ) { char ch = theStack.pop(); // pop a char, output = output + ch; // append to output } return output; } // end doRev() //-------------------------------------------------------------> } // end class Reverser //////////////////////////////////////////////////////////////// class ReverseApp { public static void main(String[] args) throws IOException { String input, output; while(true) { System.out.print("Enter a string: "); System.out.flush(); input = getString(); // read a string from kbd if( input.equals("") ) // quit if [Enter] break; // make a Reverser Reverser theReverser = new Reverser(input); output = theReverser.doRev(); // use it System.out.println("Reversed: " + output); } // end while } // end main() //------------------------------------------------------------- public static String getString() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF8" )); String s = br.readLine(); return s; } //------------------------------------------------------------- } // end class ReverseApp