以下实例演示了使用用户自定义的方法 StringReverserThroughStack() 来实现字符串反转:
import java.io.IOException;
public class StringReverserThroughStack {
private String input;
private String output;
public StringReverserThroughStack(String in) {
input = in;
}
public String doRev() {
int stackSize = input.length();
Stack theStack = new Stack(stackSize);
for (int i = 0; i
以上代码运行输出结果为:
反转前: www.w3cschool.cc 反转后: cc.loohcsc3w.www
自学教程