Problem pro[] = new Problem[num]; Random r = new Random();//随机数 int a, b;//两个一位整数 char symbol;//四则运算符号 char ops[] = {'+', '-', '*', '/'}; for (int i = 0; i < num; i++) { a = r.nextInt(9); b = r.nextInt(9); symbol = ops[r.nextInt(4)]; String standard = "";//算术题正确答案 String title = "";//题目 switch (symbol) { case '+': standard = String.valueOf(a + b); title = a + "+" + b; break; case '-': standard = String.valueOf(a - b); title = a + "-" + b; break; case '*': standard = String.valueOf(a * b); title = a + "*" + b; break; case '/': standard = String.valueOf((float) a / b); title = a + "/" + b; break; }%><jsp:useBean id="QUESTION" class="newpackage.Problem" scope="session"></jsp:useBean><jsp:setProperty name="QUESTION" property="question" value="<%=title%>"/><jsp:setProperty name="QUESTION" property="standardanswer" value="<%=standard%>"/><% pro[i] = QUESTION; }然后我在另一页面输出 (令num=4)结果给的题目都一样
1 回答
已采纳
慕勒0069038
TA贡献143条经验 获得超39个赞
我觉得问题出在class="newpackage.Problem" 他只被实例化一次,因为最后的id是一样的 每次都是去修改他的值 赋予变量的时候(pro[i] = QUESTION;)给的是他被实例化的那个地址 setpropert应该执行了4次 你试试 改成 id="QUESTION<%=i%>"
添加回答
举报
0/150
提交
取消