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)
结果给的题目都一样
慕勒0069038