四则运算

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>出题</title>
</head>
<body>
<form action="chuti.jsp" method="post">
<center>
<h2>自动出题</h2>
<h3><font>出题类型:<input type="radio" name="type" value="zhengshu">整数
<input type="radio" name="type" value="zhenfenshu">真分数
<input type="radio" name="type" value="douyou">均存在</font></h3>
<h3><font>出题数:<input type="text" name ="chutishu" ></font><br></h3>
</center>
</form>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>出题</title>
</head>
<%!
public String putong(){
char [] a=new char[4];
a[0]='+';
a[1]='-';
a[2]='*';
a[3]='/';
int num1=(int)(Math.random()*10+1);
int num2=(int)(Math.random()*10+1);
int num=(int)(Math.random()*4+0);
String s=num1+" "+a[num]+" "+num2;
return s;
}
%>
<%!
public String zhenfenshu(){
char [] a=new char[4];String m,n="";
a[0]='+';
a[1]='-';
a[2]='*';
a[3]='/';
int num1=(int)(Math.random()*10+1);
int num2=(int)(Math.random()*10+1);
for(;num1==num2;num1=(int)(Math.random()*10+1),num2=(int)(Math.random()*10+1)){}
if(num1<num2){
m=num1+"/"+num2;
}
else
m=num2+"/"+num1;

for(num1=(int)(Math.random()*10+1),num2=(int)(Math.random()*10+1);num1==num2;num1=(int)(Math.random()*10+1),num2=(int)(Math.random()*10+1)){}

if(num1<num2){
n=num1+"/"+num2;
}
else
n=num2+"/"+num1;

int num=(int)(Math.random()*4+0);
String s=m+" "+a[num]+" "+n;

return s;
}%>

<body>
<%
String type = (String)request.getParameter("type");
int chutishu=Integer.parseInt(request.getParameter("chutishu"));
int j=0;
String []a=new String [chutishu];

for(j=0;j<chutishu;j++){
if(type.equals("zhengshu"))
a[j]=putong();
else if(type.equals("zhenfenshu"))
a[j]=zhenfenshu();
else if(type.equals("douyou")){
int m=(int)(Math.random()*2+1);
if(m==1)
a[j]=putong();
else if(m==2)
a[j]=zhenfenshu();
}

for(int k=0;k<j;k++){
if(a[k].equals(a[j]))
{j--;break;}
else
continue;
}

}

for(j=0;j<chutishu;j++){%>
<%=j+1+" 、"+a[j]%><br>
<%} %>

</body>
</html>

原文地址:https://www.cnblogs.com/ylx111/p/6492182.html