scwcd的考试,测试代码,如果希望参加此类考试将非常的有帮助
源代码在线查看: servleta.java
package scwcd.ch08;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class ServletA extends HttpServlet {
char stack[] = new char[100];
int idx;
public void init(){
stack[0]='A';
stack[1]='B';
stack[2]='C';
idx = 3;
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=GB2312");
PrintWriter out = response.getWriter();
out.println("");
out.println("栈数据存取测试");
out.println("");
char c = generateChar();
out.println("产生的字符为: " + c );
out.println(" ==> 调用 push() 将 " + c + " 存入数组...");
push(c);
out.println("");
out.println("调用 pop() 从数组取出一个字符");
out.println(" ==> 结果为: " + pop());
out.println("");
}
public char pop() {
idx--;
return stack[idx];
}
public void push(char c){
stack[idx]=c;
idx++;
}
public char generateChar(){
char c = (char) (65 + 25 * (Math.random()));
return c;
}
}