<%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <html>
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7 <title>Insert title here</title>
8 <style type="text/css">
9 body
10 {
11 background-image: url(image/19.jpg);
12 }
13 </style>
14 </head>
15 <body>
16 <%
17 try
18 {
19 int tishu=Integer.parseInt(request.getParameter("geshu"));
20 int fanwei=Integer.parseInt(request.getParameter("fanwei"));
21 session.setAttribute("tishu", tishu);
22 session.setAttribute("fanwei", fanwei);
23 response.setHeader("refresh","0;url = zhengshu.jsp");
24 }
25 catch(Exception e)
26 {
27 %>
28 <script type="text/javascript">
29 alert("输入错误,点击确定返回重新输入!!!")
30 </script>
31 <%
32 response.setHeader("refresh","0;url = error.jsp");
33 }
34 %>
35 </body>
36 </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>Insert title here</title>
<style type="text/css">
body
{
background-image: url(image/7.jpg);
}
</style>
</head>
<body>
<form id="form2" name="form2" method="post" action="chaundi.jsp">
<div style="text-align:center;color:#F09">
<br>
<br>
<br>
<br>
<br>
<br>
请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
<input name="" type="submit" value="提交" />
</div>
</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>Insert title here</title>
<style type="text/css">
body
{
background-image: url(image/19.jpg);
}
</style>
</head>
<body>
<%
try
{
int tishu=Integer.parseInt(request.getParameter("geshu"));
int fanwei=Integer.parseInt(request.getParameter("fanwei"));
session.setAttribute("tishu", tishu);
session.setAttribute("fanwei", fanwei);
response.setHeader("refresh","0;url = fenshu.jsp");
}
catch(Exception e)
{
%>
<script type="text/javascript">
alert("输入错误,点击确定返回重新输入!!!")
</script>
<%
response.setHeader("refresh","0;url = fenerror.jsp");
}
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
2 pageEncoding="UTF-8"%>
3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <html>
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7 <title>Insert title here</title>
8 <style type="text/css">
9 body
10 {
11 background-image: url(image/7.jpg);
12 }
13 </style>
14 </head>
15 <body>
16 <form id="form2" name="form2" method="post" action="fenchuandi.jsp">
17 <div style="text-align:center;color:#F09">
18 <br>
19 <br>
20 <br>
21 <br>
22 <br>
23 <br>
24 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
25 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
26 <input name="" type="submit" value="提交" />
27 </div>
28 </form>
29 </body>
30 </html>
1 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 2 pageEncoding="UTF-8" import="java.util.Random"%> 3 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 4 <html> 5 5 <head> 6 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 7 <title>Insert title here</title> 8 8 <style type="text/css"> 9 9 body 10 10 { 11 11 background-image: url(image/4.jpg); 12 12 } 13 13 </style> 14 14 </head> 15 15 <body> 16 16 <%! 17 17 class Suan2//真分数的运算类 18 18 { 19 19 public int m,n,x,y,c;//定义4个变量,还有一个符号变量 20 20 public Random random=new Random(); 21 21 String s;//生成的计算式储存咋m里面 22 22 int fanwei; 23 23 public void shengcheng(int fanwei1) 24 24 { 25 25 fanwei=fanwei1; 26 26 c=random.nextInt(4); 27 27 x=random.nextInt(fanwei); 28 28 y=random.nextInt(fanwei); 29 29 m=random.nextInt(fanwei); 30 30 n=random.nextInt(fanwei);//生成4个随机数在50以内,赋给x,y,m,n 31 31 String fuhao; 32 32 for(int i=0;;i++) 33 33 { 34 34 if(x==0)//不能生成0 35 35 { 36 36 x=random.nextInt(fanwei); 37 37 } 38 38 else 39 39 { 40 40 break; 41 41 } 42 42 } 43 43 for(int i=0;;i++) 44 44 { 45 45 if(y==0||y==x)//不能生成0 46 46 { 47 47 y=random.nextInt(fanwei); 48 48 } 49 49 else 50 50 { 51 51 break; 52 52 } 53 53 } 54 54 for(int i=0;;i++) 55 55 { 56 56 if(m==0)//不能生成0 57 57 { 58 58 m=random.nextInt(fanwei); 59 59 } 60 60 else 61 61 { 62 62 break; 63 63 } 64 64 } 65 65 for(int i=0;;i++) 66 66 { 67 67 if(n==0||m==n)//不能生成0 68 68 { 69 69 n=random.nextInt(fanwei); 70 70 } 71 71 else 72 72 { 73 73 break; 74 74 } 75 75 } 76 76 if(c==0)//通整数一样,0是加法,1减法,2乘法,3除法 77 77 { 78 78 fuhao="+"; 79 79 } 80 80 else if(c==1) 81 81 { 82 82 fuhao="-"; 83 83 } 84 84 else if(c==2) 85 85 { 86 86 fuhao="*"; 87 87 } 88 88 else 89 89 { 90 90 fuhao="/"; 91 91 } 92 92 int gongyue=Gongyue(x,y); 93 93 x=x/gongyue; 94 94 y=y/gongyue; 95 95 gongyue=Gongyue(m,n); 96 96 m=m/gongyue; 97 97 n=n/gongyue; 98 98 } 99 99 public String shuchu()//定义输出函数 100 100 { 101 101 if(c==0) 102 102 { 103 103 if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果 104 104 { 105 105 s=y+"/"+x+" + "+n+"/"+m+"="; 106 106 return jisuan(x,y,m,n,c);//返回计算结果 107 107 } 108 108 else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果 109 109 { 110 110 s=y+"/"+x+" + "+m+"/"+n+"="; 111 111 return jisuan(x,y,n,m,c);//返回计算结果 112 112 } 113 113 else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果 114 114 { 115 115 s=x+"/"+y+" + "+n+"/"+m+"="; 116 116 return jisuan(y,x,m,n,c);//返回计算结果 117 117 } 118 118 else//生成的分母必须大于分子,输出不同的结果 119 119 { 120 120 s=x+"/"+y+" + "+m+"/"+n+"="; 121 121 return jisuan(y,x,n,m,c);//返回计算结果 122 122 } 123 123 } 124 124 else if(c==1) 125 125 { 126 126 double x1=Double.parseDouble(String.valueOf(x)); 127 127 double y1=Double.parseDouble(String.valueOf(y)); 128 128 double m1=Double.parseDouble(String.valueOf(m)); 129 129 double n1=Double.parseDouble(String.valueOf(n)); 130 130 if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果 131 131 { 132 132 if((y1/x1)>(n1/m1)) 133 133 { 134 134 s=y+"/"+x+" - "+n+"/"+m+"="; 135 135 return jisuan(x,y,m,n,c);//返回计算结果 136 136 } 137 137 else 138 138 { 139 139 s=n+"/"+m+" - "+y+"/"+x+"="; 140 140 return jisuan(m,n,x,y,c);//返回计算结果 141 141 } 142 142 } 143 143 else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果 144 144 { 145 145 if((y1/x1)>(m1/n1))//减数必须大于被减数 146 146 { 147 147 s=y+"/"+x+" - "+m+"/"+n+"="; 148 148 return jisuan(x,y,n,m,c);//返回计算结果 149 149 } 150 150 else//减数必须大于被减数 151 151 { 152 152 s=m+"/"+n+" - "+y+"/"+x+"="; 153 153 return jisuan(n,m,x,y,c);//返回计算结果 154 154 } 155 155 } 156 156 else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果 157 157 { 158 158 if((x1/y1)>(n1/m1))//减数必须大于被减数 159 159 { 160 160 s=x+"/"+y+" - "+n+"/"+m+"="; 161 161 return jisuan(y,x,m,n,c); 162 162 } 163 163 else//减数必须大于被减数 164 164 { 165 165 s=n+"/"+m+" - "+x+"/"+y+"="; 166 166 return jisuan(m,n,y,x,c);//返回计算结果 167 167 } 168 168 } 169 169 else 170 170 { 171 171 if((x1/y1)>(m1/n1))//生成的分母必须大于分子,输出不同的结果//减数必须大于被减数 172 172 { 173 173 s=x+"/"+y+" - "+m+"/"+n+"="; 174 174 return jisuan(y,x,n,m,c);//返回计算结果 175 175 } 176 176 else//减数必须大于被减数 177 177 { 178 178 s=m+"/"+n+" - "+x+"/"+y+"="; 179 179 return jisuan(n,m,y,x,c);//返回计算结果 180 180 } 181 181 } 182 182 } 183 183 else if(c==2) 184 184 { 185 185 if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果 186 186 { 187 187 s=y+"/"+x+" * "+n+"/"+m+"="; 188 188 return jisuan(x,y,m,n,c);//返回计算结果 189 189 } 190 190 else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果 191 191 { 192 192 s=y+"/"+x+" * "+m+"/"+n+"="; 193 193 return jisuan(x,y,n,m,c);//返回计算结果 194 194 } 195 195 else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果 196 196 { 197 197 s=x+"/"+y+" * "+n+"/"+m+"="; 198 198 return jisuan(y,x,m,n,c); 199 199 } 200 200 else//生成的分母必须大于分子,输出不同的结果 201 201 { 202 202 s=x+"/"+y+" * "+m+"/"+n+"="; 203 203 return jisuan(y,x,n,m,c);//返回计算结果 204 204 } 205 205 } 206 206 else 207 207 { 208 208 if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果 209 209 { 210 210 s=y+"/"+x+" / "+n+"/"+m+"="; 211 211 return jisuan(x,y,m,n,c);//返回计算结果 212 212 } 213 213 else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果 214 214 { 215 215 s=y+"/"+x+" / "+m+"/"+n+"="; 216 216 return jisuan(x,y,n,m,c);//返回计算结果 217 217 } 218 218 else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果 219 219 { 220 220 s=x+"/"+y+" / "+n+"/"+m+"="; 221 221 return jisuan(y,x,m,n,c);//返回计算结果 222 222 } 223 223 else//生成的分母必须大于分子,输出不同的结果 224 224 { 225 225 s=x+"/"+y+" / "+m+"/"+n+"="; 226 226 return jisuan(y,x,n,m,c);//返回计算结果 227 227 } 228 228 } 229 229 } 230 230 public String jisuan(int a,int b,int c,int d,int m)//计算结果的函数 231 231 { 232 232 String daan; 233 233 int gongyue,gongbei; 234 234 if(m==0)//加法计算的结果算法 235 235 { 236 236 gongbei=Gongbei(a,c);//求两个分母的最小公倍数 237 237 int s1,s2,s3; 238 238 s1=gongbei/a; 239 239 s2=gongbei/c; 240 240 s3=b*s1+d*s2; 241 241 if(s3==gongbei) 242 242 { 243 243 return("1"); 244 244 } 245 245 else 246 246 { 247 247 gongyue=Gongyue(s3,gongbei); 248 248 int fenzi=s3/gongyue,fenmu=gongbei/gongyue; 249 249 if(fenzi<fenmu) 250 250 { 251 251 daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分 252 252 return daan; 253 253 } 254 254 else 255 255 { 256 256 int zhi=fenzi/fenmu; 257 257 daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分 258 258 return daan; 259 259 } 260 260 } 261 261 } 262 262 else if(m==1)//减法计算的结果算法 263 263 { 264 264 gongbei=Gongbei(a,c); 265 265 int s1,s2,s3; 266 266 s1=gongbei/a; 267 267 s2=gongbei/c; 268 268 s3=b*s1-d*s2; 269 269 if(s3==gongbei) 270 270 { 271 271 return("1"); 272 272 } 273 273 else 274 274 { 275 275 if(s3==0) 276 276 { 277 277 daan=String.valueOf("0"); 278 278 return daan; 279 279 } 280 280 else 281 281 { 282 282 gongyue=Gongyue(s3,gongbei); 283 283 int fenzi=s3/gongyue,fenmu=gongbei/gongyue; 284 284 if(fenzi<fenmu) 285 285 { 286 286 daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分 287 287 return daan; 288 288 } 289 289 else 290 290 { 291 291 int zhi=fenzi/fenmu; 292 292 daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分 293 293 return daan; 294 294 } 295 295 } 296 296 } 297 297 } 298 298 else if(m==2)//乘法计算的结果算法 299 299 { 300 300 int s1,s2; 301 301 s1=a*c; 302 302 s2=b*d; 303 303 if(s1==s2) 304 304 { 305 305 return("1"); 306 306 } 307 307 else 308 308 { 309 309 gongyue=Gongyue(s1,s2); 310 310 int fenzi=s2/gongyue,fenmu=s1/gongyue; 311 311 if(fenzi<fenmu) 312 312 { 313 313 daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分 314 314 return daan; 315 315 } 316 316 else 317 317 { 318 318 int zhi=fenzi/fenmu; 319 319 daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分 320 320 return daan; 321 321 } 322 322 } 323 323 } 324 324 else//除法计算的结果算法 325 325 { 326 326 int s1,s2; 327 327 s1=a*d; 328 328 s2=b*c; 329 329 if(s1==s2) 330 330 { 331 331 return("1"); 332 332 } 333 333 else 334 334 { 335 335 gongyue=Gongyue(s1,s2); 336 336 int fenzi=s2/gongyue,fenmu=s1/gongyue; 337 337 if(fenzi<fenmu) 338 338 { 339 339 daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分 340 340 return daan; 341 341 } 342 342 else 343 343 { 344 344 int zhi=fenzi/fenmu; 345 345 daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分 346 346 return daan; 347 347 } 348 348 } 349 349 } 350 350 } 351 351 public int Gongbei(int a,int c)//求最小公倍数的函数 352 352 { 353 353 int gongbei; 354 354 if(a>c) 355 355 { 356 356 gongbei=a;//公倍数从大的开始 357 357 while(gongbei<=a*c) 358 358 { 359 359 if(gongbei%a==0&&gongbei%c==0) 360 360 { 361 361 break; 362 362 } 363 363 gongbei++; 364 364 } 365 365 } 366 366 else 367 367 { 368 368 gongbei=c;//公倍数从大的开始 369 369 while(gongbei<=a*c) 370 370 { 371 371 if(gongbei%a==0&&gongbei%c==0) 372 372 { 373 373 break; 374 374 } 375 375 gongbei++; 376 376 } 377 377 } 378 378 return gongbei; 379 379 } 380 380 public int Gongyue(int gongbei,int s3)//求最大公约数的函数 381 381 { 382 382 int i=1,gongyue=0; 383 383 if(gongbei>s3)//公约数从1到最小的数 384 384 { 385 385 while(i<=s3) 386 386 { 387 387 if(gongbei%i==0&&s3%i==0) 388 388 { 389 389 gongyue=i; 390 390 } 391 391 i++; 392 392 } 393 393 return gongyue; 394 394 } 395 395 else 396 396 { 397 397 while(i<=gongbei) 398 398 { 399 399 if(gongbei%i==0&&s3%i==0) 400 400 { 401 401 gongyue=i; 402 402 } 403 403 i++; 404 404 } 405 405 return gongyue; 406 406 } 407 407 } 408 408 public int jianyan(String a[],int l)//检验是否生成重复计算式的函数 409 409 { 410 410 int flag=1; 411 411 for(int i=0;i<l;i++) 412 412 { 413 413 if(s.equals(a[i])) 414 414 { 415 415 flag=0; 416 416 break; 417 417 } 418 418 } 419 419 return flag; 420 420 } 421 421 } 422 422 Random random=new Random(); 423 423 int tishu; 424 424 int fanwei; 425 425 int m=0; 426 426 String shuju[]=new String[10000]; 427 427 int flag=0; 428 428 Suan2 a=new Suan2(); 429 429 String daan,daan1; 430 430 %> 431 431 <% 432 432 tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); 433 433 fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei")))); 434 434 session.setAttribute("tishu", tishu); 435 435 if(m<tishu) 436 436 { 437 437 a.shengcheng(fanwei); 438 438 String f=a.shuchu(); 439 439 shuju[m]=a.s; 440 440 flag=a.jianyan(shuju, m);//返回是否有重复 441 441 if(flag==1)//如果没有就是1 442 442 { 443 443 if(m+1==tishu) 444 444 {daan=a.shuchu(); 445 445 session.setAttribute("shuju", shuju[m]); 446 446 session.setAttribute("daan", daan); 447 447 session.setAttribute("m", m); 448 448 %> 449 449 <form id="form2" name="form2" method="post" action="fenshuhuoqu.jsp"> 450 450 <div style="text-align:center"> 451 451 <br> 452 452 <br> 453 453 <br> 454 454 <br> 455 455 <br> 456 456 <br> 457 457 <br> 458 458 <br> 459 459 <br> 460 460 <br> 461 461 <br> 462 462 <br> 463 463 <br> 464 464 <%out.print(m+1+"."+shuju[m]+"="); 465 465 m=0;%> 466 466 <br> 467 467 <br> 468 468 <br> 469 469 <br> 470 470 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> 471 471 <input name="" type="submit" value="提交" /> 472 472 </div> 473 473 </form> 474 474 <% 475 475 } 476 476 else 477 477 { 478 478 daan=a.shuchu(); 479 479 session.setAttribute("shuju", shuju[m]); 480 480 session.setAttribute("daan", daan); 481 481 session.setAttribute("m", m); 482 482 %> 483 483 <form id="form2" name="form2" method="post" action="fenshuhuoqu.jsp"> 484 484 <div style="text-align:center"> 485 485 <br> 486 486 <br> 487 487 <br> 488 488 <br> 489 489 <br> 490 490 <br> 491 491 <br> 492 492 <br> 493 493 <br> 494 494 <br> 495 495 <br> 496 496 <br> 497 497 <br> 498 498 <%out.print(m+1+"."+shuju[m]+"=");%> 499 499 <br> 500 500 <br> 501 501 <br> 502 502 <br> 503 503 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> 504 504 <input name="" type="submit" value="下一个" /> 505 505 </div> 506 506 </form> 507 507 <% 508 508 m++; 509 509 flag=0; 510 510 } 511 511 512 512 } 513 513 else 514 514 { 515 515 response.setHeader("refresh","0;url = zhengshu.jsp"); 516 516 } 517 517 } 518 518 %> 519 519 </body> 520 520 </html>
1 1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 2 pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%> 3 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 4 <html> 5 5 <head> 6 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 7 <title>Insert title here</title> 8 8 <style type="text/css"> 9 9 body 10 10 { 11 11 background-image: url(image/18.jpg); 12 12 } 13 13 </style> 14 14 </head> 15 15 <body> 16 16 <%! 17 17 int tishu1; 18 18 String error="",zhengque=""; 19 19 %> 20 20 <% 21 21 try 22 22 { 23 23 Connection con = null; //定义一个MYSQL链接对象 24 24 Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动 25 25 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL 26 26 java.sql.Statement stmt; //创建声明 27 27 stmt = con.createStatement(); 28 28 String shuju=String.valueOf(session.getAttribute("shuju")); 29 29 String daan=String.valueOf(session.getAttribute("daan")); 30 30 int m=Integer.parseInt(String.valueOf(session.getAttribute("m"))); 31 31 tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); 32 32 String daan1=request.getParameter("daan1"); 33 33 String sql="INSERT INTO 真分数的四则计算 (shizi,result,userresult) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')"; 34 34 stmt.executeUpdate(sql); 35 35 if(daan.equals(daan1)) 36 36 { 37 37 zhengque=zhengque+String.valueOf(m+1)+","; 38 38 } 39 39 else 40 40 { 41 41 error=error+String.valueOf(m+1)+","; 42 42 } 43 43 if(m+1==tishu1) 44 44 { 45 45 sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')"; 46 46 stmt.executeUpdate(sql); 47 47 48 48 %> 49 49 <form id="form2" name="form2" method="post" action="xuanze.html"> 50 50 <div style="text-align:center;color:#F00"> 51 51 <strong> 52 52 <br> 53 53 <br> 54 54 <br> 55 55 <br> 56 56 <br> 57 57 <br> 58 58 <br> 59 59 <br> 60 60 <br> 61 61 <br> 62 62 <br> 63 63 <br> 64 64 <br> 65 65 <br> 66 66 <% 67 67 out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); 68 68 zhengque=""; 69 69 error=""; %> 70 70 <input name="" type="submit" value="确定" /> 71 71 </strong> 72 72 </div> 73 73 </form> 74 74 <% 75 75 } 76 76 else 77 77 { 78 78 response.setHeader("refresh","0;url = fenshu.jsp"); 79 79 } 80 80 } 81 81 catch (Exception e) 82 82 { 83 83 System.out.print("MYSQL ERROR:" + e.getMessage()); 84 84 } 85 85 %> 86 86 </body> 87 87 </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.Random"%> <!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>Insert title here</title> <style type="text/css"> body { background-image: url(image/4.jpg); } </style> </head> <body> <%! class Suan1//生成整数计算的类 { public int x,y,c;//定义两个变量,还有一个符号变量 public Random random=new Random();//定义随机数 String m;//生成的计算式储存咋m里面 int fanwei; public String shengcheng(int fanwei1)//自动生成数的函数 { fanwei=fanwei1; c=random.nextInt(4);//生成符号 String fuhao; x=random.nextInt(fanwei);//生成100以内的自然数 y=random.nextInt(fanwei); if(c==0)//0是加法 { fuhao="+"; m=String.valueOf(x)+fuhao+String.valueOf(y); } else if(c==1)//1是减法 { fuhao="-"; if(x>=y) { m=String.valueOf(x)+fuhao+String.valueOf(y); } else { m=String.valueOf(y)+fuhao+String.valueOf(x); } } else if(c==2) { fuhao="*"; m=String.valueOf(x)+fuhao+String.valueOf(y); } else { fuhao="/"; for(int i=0;;i++) { if(y==0) { y=random.nextInt(fanwei); } else { break; } } m=String.valueOf(x)+fuhao+String.valueOf(y); } return m; } public String shuchu()//定义输出函数 { if(c==0) { return (String.valueOf(x+y));//并且返回计算的结果 } else if(c==1) { if(x>=y)//将较大的数放在前面,不能出现负数 { return (String.valueOf(x-y)); } else { return (String.valueOf(y-x)); } } else if(c==2) { return (String.valueOf(x*y)); } else { if(x%y==0) { return (String.valueOf(x/y)); } else { if(x>y) { int shang=x/y; int yushu=x-y*shang; return (String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y)); } else { return (String.valueOf(x)+"/"+String.valueOf(y)); } } } } public int fanhuic() { return c; } public int jianyan(String a[],int s)//检验是否有重复的式子,如果有返回0,没有就返回1 { int flag=1; for(int i=0;i<s;i++) { if(m.equals(a[i]))//数组a里面是生成的式子 { flag=0; break; } } return flag; } } class Suan2//真分数的运算类 { public int m,n,x,y,c;//定义4个变量,还有一个符号变量 public Random random=new Random(); String s;//生成的计算式储存咋m里面 int fanwei; public void shengcheng(int fanwei1) { fanwei=fanwei1; c=random.nextInt(4); x=random.nextInt(fanwei); y=random.nextInt(fanwei); m=random.nextInt(fanwei); n=random.nextInt(fanwei);//生成4个随机数在50以内,赋给x,y,m,n String fuhao; for(int i=0;;i++) { if(x==0)//不能生成0 { x=random.nextInt(fanwei); } else { break; } } for(int i=0;;i++) { if(y==0||y==x)//不能生成0 { y=random.nextInt(fanwei); } else { break; } } for(int i=0;;i++) { if(m==0)//不能生成0 { m=random.nextInt(fanwei); } else { break; } } for(int i=0;;i++) { if(n==0||m==n)//不能生成0 { n=random.nextInt(fanwei); } else { break; } } if(c==0)//通整数一样,0是加法,1减法,2乘法,3除法 { fuhao="+"; } else if(c==1) { fuhao="-"; } else if(c==2) { fuhao="*"; } else { fuhao="/"; } int gongyue=Gongyue(x,y); x=x/gongyue; y=y/gongyue; gongyue=Gongyue(m,n); m=m/gongyue; n=n/gongyue; } public String shuchu()//定义输出函数 { if(c==0) { if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果 { s=y+"/"+x+" + "+n+"/"+m+"="; return jisuan(x,y,m,n,c);//返回计算结果 } else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果 { s=y+"/"+x+" + "+m+"/"+n+"="; return jisuan(x,y,n,m,c);//返回计算结果 } else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果 { s=x+"/"+y+" + "+n+"/"+m+"="; return jisuan(y,x,m,n,c);//返回计算结果 } else//生成的分母必须大于分子,输出不同的结果 { s=x+"/"+y+" + "+m+"/"+n+"="; return jisuan(y,x,n,m,c);//返回计算结果 } } else if(c==1) { double x1=Double.parseDouble(String.valueOf(x)); double y1=Double.parseDouble(String.valueOf(y)); double m1=Double.parseDouble(String.valueOf(m)); double n1=Double.parseDouble(String.valueOf(n)); if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果 { if((y1/x1)>(n1/m1)) { s=y+"/"+x+" - "+n+"/"+m+"="; return jisuan(x,y,m,n,c);//返回计算结果 } else { s=n+"/"+m+" - "+y+"/"+x+"="; return jisuan(m,n,x,y,c);//返回计算结果 } } else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果 { if((y1/x1)>(m1/n1))//减数必须大于被减数 { s=y+"/"+x+" - "+m+"/"+n+"="; return jisuan(x,y,n,m,c);//返回计算结果 } else//减数必须大于被减数 { s=m+"/"+n+" - "+y+"/"+x+"="; return jisuan(n,m,x,y,c);//返回计算结果 } } else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果 { if((x1/y1)>(n1/m1))//减数必须大于被减数 { s=x+"/"+y+" - "+n+"/"+m+"="; return jisuan(y,x,m,n,c); } else//减数必须大于被减数 { s=n+"/"+m+" - "+x+"/"+y+"="; return jisuan(m,n,y,x,c);//返回计算结果 } } else { if((x1/y1)>(m1/n1))//生成的分母必须大于分子,输出不同的结果//减数必须大于被减数 { s=x+"/"+y+" - "+m+"/"+n+"="; return jisuan(y,x,n,m,c);//返回计算结果 } else//减数必须大于被减数 { s=m+"/"+n+" - "+x+"/"+y+"="; return jisuan(n,m,y,x,c);//返回计算结果 } } } else if(c==2) { if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果 { s=y+"/"+x+" * "+n+"/"+m+"="; return jisuan(x,y,m,n,c);//返回计算结果 } else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果 { s=y+"/"+x+" * "+m+"/"+n+"="; return jisuan(x,y,n,m,c);//返回计算结果 } else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果 { s=x+"/"+y+" * "+n+"/"+m+"="; return jisuan(y,x,m,n,c); } else//生成的分母必须大于分子,输出不同的结果 { s=x+"/"+y+" * "+m+"/"+n+"="; return jisuan(y,x,n,m,c);//返回计算结果 } } else { if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果 { s=y+"/"+x+" / "+n+"/"+m+"="; return jisuan(x,y,m,n,c);//返回计算结果 } else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果 { s=y+"/"+x+" / "+m+"/"+n+"="; return jisuan(x,y,n,m,c);//返回计算结果 } else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果 { s=x+"/"+y+" / "+n+"/"+m+"="; return jisuan(y,x,m,n,c);//返回计算结果 } else//生成的分母必须大于分子,输出不同的结果 { s=x+"/"+y+" / "+m+"/"+n+"="; return jisuan(y,x,n,m,c);//返回计算结果 } } } public String jisuan(int a,int b,int c,int d,int m)//计算结果的函数 { String daan; int gongyue,gongbei; if(m==0)//加法计算的结果算法 { gongbei=Gongbei(a,c);//求两个分母的最小公倍数 int s1,s2,s3; s1=gongbei/a; s2=gongbei/c; s3=b*s1+d*s2; if(s3==gongbei) { return("1"); } else { gongyue=Gongyue(s3,gongbei); int fenzi=s3/gongyue,fenmu=gongbei/gongyue; if(fenzi<fenmu) { daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分 return daan; } else { int zhi=fenzi/fenmu; daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分 return daan; } } } else if(m==1)//减法计算的结果算法 { gongbei=Gongbei(a,c); int s1,s2,s3; s1=gongbei/a; s2=gongbei/c; s3=b*s1-d*s2; if(s3==gongbei) { return("1"); } else { if(s3==0) { daan=String.valueOf("0"); return daan; } else { gongyue=Gongyue(s3,gongbei); int fenzi=s3/gongyue,fenmu=gongbei/gongyue; if(fenzi<fenmu) { daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分 return daan; } else { int zhi=fenzi/fenmu; daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分 return daan; } } } } else if(m==2)//乘法计算的结果算法 { int s1,s2; s1=a*c; s2=b*d; if(s1==s2) { return("1"); } else { gongyue=Gongyue(s1,s2); int fenzi=s2/gongyue,fenmu=s1/gongyue; if(fenzi<fenmu) { daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分 return daan; } else { int zhi=fenzi/fenmu; daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分 return daan; } } } else//除法计算的结果算法 { int s1,s2; s1=a*d; s2=b*c; if(s1==s2) { return("1"); } else { gongyue=Gongyue(s1,s2); int fenzi=s2/gongyue,fenmu=s1/gongyue; if(fenzi<fenmu) { daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分 return daan; } else { int zhi=fenzi/fenmu; daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分 return daan; } } } } public int Gongbei(int a,int c)//求最小公倍数的函数 { int gongbei; if(a>c) { gongbei=a;//公倍数从大的开始 while(gongbei<=a*c) { if(gongbei%a==0&&gongbei%c==0) { break; } gongbei++; } } else { gongbei=c;//公倍数从大的开始 while(gongbei<=a*c) { if(gongbei%a==0&&gongbei%c==0) { break; } gongbei++; } } return gongbei; } public int Gongyue(int gongbei,int s3)//求最大公约数的函数 { int i=1,gongyue=0; if(gongbei>s3)//公约数从1到最小的数 { while(i<=s3) { if(gongbei%i==0&&s3%i==0) { gongyue=i; } i++; } return gongyue; } else { while(i<=gongbei) { if(gongbei%i==0&&s3%i==0) { gongyue=i; } i++; } return gongyue; } } public int jianyan(String a[],int l)//检验是否生成重复计算式的函数 { int flag=1; for(int i=0;i<l;i++) { if(s.equals(a[i])) { flag=0; break; } } return flag; } } int tishu; int fanwei; int m=0; Random random=new Random(); String shuju[]=new String[10000]; int flag=0; Suan2 a=new Suan2(); Suan1 b=new Suan1(); String daan,daan1; %> <% tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei")))); session.setAttribute("tishu", tishu); if(m<tishu) { int t=random.nextInt(2); if(t==0) { a.shengcheng(fanwei); String f=a.shuchu(); shuju[m]=a.s; flag=a.jianyan(shuju, m);//返回是否有重复 if(flag==1)//如果没有就是1 { if(m+1==tishu) {daan=a.shuchu(); session.setAttribute("shuju", shuju[m]); session.setAttribute("daan", daan); session.setAttribute("m", m); %> <form id="form2" name="form2" method="post" action="fenzhenghuoqu.jsp"> <div style="text-align:center"> <%out.print(m+1+"."+shuju[m]+"="); m=0;%> <br> <br> <br> <br> <br> 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> <input name="" type="submit" value="提交" /> </div> </form> <% } else { daan=a.shuchu(); session.setAttribute("shuju", shuju[m]); session.setAttribute("daan", daan); session.setAttribute("m", m); %> <form id="form2" name="form2" method="post" action="fenzhenghuoqu.jsp"> <div style="text-align:center"> <%out.print(m+1+"."+shuju[m]+"=");%> <br> <br> <br> <br> <br> 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> <input name="" type="submit" value="下一个" /> </div> </form> <% m++; flag=0; } } else { response.setHeader("refresh","0;url = fenzheng.jsp"); } } else { shuju[m]=b.shengcheng(fanwei);//将生成的计算式储存咋数组里面 flag=b.jianyan(shuju, m);//返回是否有重复 if(flag==1)//如果没有就是1 { if(m+1==tishu) {daan=b.shuchu(); session.setAttribute("shuju", shuju[m]); session.setAttribute("daan", daan); session.setAttribute("m", m); %> <form id="form2" name="form2" method="post" action="fenzhenghuoqu.jsp"> <div style="text-align:center"> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <%out.print(m+1+"."+shuju[m]+"="); m=0;%> <br> <br> <br> <br> 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> <input name="" type="submit" value="提交" /> </div> </form> <% } else { daan=b.shuchu(); session.setAttribute("shuju", shuju[m]); session.setAttribute("daan", daan); session.setAttribute("m", m); %> <form id="form2" name="form2" method="post" action="fenzhenghuoqu.jsp"> <div style="text-align:center"> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <%out.print(m+1+"."+shuju[m]+"=");%> <br> <br> <br> <br> 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> <input name="" type="submit" value="下一个" /> </div> </form> <% m++; flag=0; } } else { response.setHeader("refresh","1;url = fenzheng.jsp"); } } } %> </body> </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <% 11 try 12 { 13 int tishu=Integer.parseInt(request.getParameter("geshu")); 14 int fanwei=Integer.parseInt(request.getParameter("fanwei")); 15 session.setAttribute("tishu", tishu); 16 session.setAttribute("fanwei", fanwei); 17 response.setHeader("refresh","0;url = fenzheng.jsp"); 18 } 19 catch(Exception e) 20 { 21 %> 22 23 <script type="text/javascript"> 24 alert("输入错误,点击确定返回重新输入!!!") 25 </script> 26 <% 27 response.setHeader("refresh","0;url = fenzhengerror.jsp"); 28 } 29 %> 30 </body> 31 </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>Insert title here</title> <style type="text/css"> body { background-image: url(image/7.jpg); } </style> </head> <body> <form id="form2" name="form2" method="post" action="fenzhengchuangdi.jsp"> <div style="text-align:center;color:#F09"> <br> <br> <br> <br> <br> <br> 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> <input name="" type="submit" value="提交" /> </div> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%> <!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>Insert title here</title> <style type="text/css"> body { background-image: url(image/18.jpg); } </style> </head> <body> <%! int tishu1; String error="",zhengque=""; %> <% try { Connection con = null; //定义一个MYSQL链接对象 Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL java.sql.Statement stmt; //创建声明 stmt = con.createStatement(); String shuju=String.valueOf(session.getAttribute("shuju")); String daan=String.valueOf(session.getAttribute("daan")); int m=Integer.parseInt(String.valueOf(session.getAttribute("m"))); tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); String daan1=request.getParameter("daan1"); String sql="INSERT INTO 整数与真分数的混合四则运算 (shizi,result,userresult) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')"; stmt.executeUpdate(sql); if(daan.equals(daan1)) { zhengque=zhengque+String.valueOf(m+1)+","; } else { error=error+String.valueOf(m+1)+","; } if(m+1==tishu1) { sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')"; stmt.executeUpdate(sql); %> <form id="form2" name="form2" method="post" action="xuanze.html"> <div style="text-align:center;color:#F00"> <strong> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <% out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); zhengque=""; error=""; %> <input name="" type="submit" value="确定" /> </strong> </div> </form> <% } else { response.setHeader("refresh","0;url = fenzheng.jsp"); } } catch (Exception e) { System.out.print("MYSQL ERROR:" + e.getMessage()); } %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%> <!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>Insert title here</title> <style type="text/css"> body { background-image: url(image/18.jpg); } </style> </head> <body> <%! int tishu1; String error="",zhengque=""; %> <% try { Connection con = null; //定义一个MYSQL链接对象 Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL java.sql.Statement stmt; //创建声明 stmt = con.createStatement(); String shuju=String.valueOf(session.getAttribute("shuju")); String daan=String.valueOf(session.getAttribute("daan")); int m=Integer.parseInt(String.valueOf(session.getAttribute("m"))); tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); String daan1=request.getParameter("daan1"); String sql="INSERT INTO 整数的四则计算 (shizi,result,userresult) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')"; stmt.executeUpdate(sql); if(daan.equals(daan1)) { zhengque=zhengque+String.valueOf(m+1)+","; } else { error=error+String.valueOf(m+1)+","; } if(m+1==tishu1) { sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')"; stmt.executeUpdate(sql); %> <form id="form2" name="form2" method="post" action="xuanze.html"> <div style="text-align:center;color:#F00"> <strong> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <% out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); zhengque=""; error=""; %> <input name="" type="submit" value="确定" /> </strong> </div> </form> <% } else { response.setHeader("refresh","0;url = zhengshu.jsp"); } } catch (Exception e) { System.out.print("MYSQL ERROR:" + e.getMessage()); } %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%> <!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>Insert title here</title> <style type="text/css"> body { background-image: url(image/18.jpg); } </style> </head> <body> <%! int tishu1; String error="",zhengque=""; %> <% try { Connection con = null; //定义一个MYSQL链接对象 Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL java.sql.Statement stmt; //创建声明 stmt = con.createStatement(); String shuju=String.valueOf(session.getAttribute("shuju")); String daan=String.valueOf(session.getAttribute("daan")); int m=Integer.parseInt(String.valueOf(session.getAttribute("m"))); tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); String daan1=request.getParameter("daan1"); String sql="INSERT INTO 整数的四则计算 (shizi,result,userresult) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')"; stmt.executeUpdate(sql); if(daan.equals(daan1)) { zhengque=zhengque+String.valueOf(m+1)+","; } else { error=error+String.valueOf(m+1)+","; } if(m+1==tishu1) { sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')"; stmt.executeUpdate(sql); %> <form id="form2" name="form2" method="post" action="xuanze.html"> <div style="text-align:center;color:#F00"> <strong> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <% out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); zhengque=""; error=""; %> <input name="" type="submit" value="确定" /> </strong> </div> </form> <% } else { response.setHeader("refresh","0;url = zhengshu.jsp"); } } catch (Exception e) { System.out.print("MYSQL ERROR:" + e.getMessage()); } %> </body> </html> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.Random"%> <!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>Insert title here</title> <style type="text/css"> body { background-image: url(image/4.jpg); } </style> </head> <body> <%! class Suan1//生成整数计算的类 { public int x,y,c;//定义两个变量,还有一个符号变量 public Random random=new Random();//定义随机数 String m;//生成的计算式储存咋m里面 int fanwei; public String shengcheng(int fanwei1)//自动生成数的函数 { fanwei=fanwei1; c=random.nextInt(4);//生成符号 String fuhao; x=random.nextInt(fanwei);//生成100以内的自然数 y=random.nextInt(fanwei); if(c==0)//0是加法 { fuhao="+"; m=String.valueOf(x)+fuhao+String.valueOf(y); } else if(c==1)//1是减法 { fuhao="-"; if(x>=y) { m=String.valueOf(x)+fuhao+String.valueOf(y); } else { m=String.valueOf(y)+fuhao+String.valueOf(x); } } else if(c==2) { fuhao="*"; m=String.valueOf(x)+fuhao+String.valueOf(y); } else { fuhao="/"; for(int i=0;;i++) { if(y==0) { y=random.nextInt(fanwei); } else { break; } } m=String.valueOf(x)+fuhao+String.valueOf(y); } return m; } public String shuchu()//定义输出函数 { if(c==0) { return (String.valueOf(x+y));//并且返回计算的结果 } else if(c==1) { if(x>=y)//将较大的数放在前面,不能出现负数 { return (String.valueOf(x-y)); } else { return (String.valueOf(y-x)); } } else if(c==2) { return (String.valueOf(x*y)); } else { if(x%y==0) { return (String.valueOf(x/y)); } else { if(x>y) { int shang=x/y; int yushu=x-y*shang; return (String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y)); } else { return (String.valueOf(x)+"/"+String.valueOf(y)); } } } } public int fanhuic() { return c; } public String jisuan() { if(c==0) { return (String.valueOf(x+y));//并且返回计算的结果 } else if(c==1) { if(x>=y)//将较大的数放在前面,不能出现负数 { return (String.valueOf(x-y)); } else { return (String.valueOf(y-x)); } } else if(c==2) { return (String.valueOf(x*y)); } else { if(x%y==0) { return (String.valueOf(x/y)); } else { return (String.valueOf(x)+"/"+String.valueOf(y)); } } } public int jianyan(String a[],int s)//检验是否有重复的式子,如果有返回0,没有就返回1 { int flag=1; for(int i=0;i<s;i++) { if(m.equals(a[i]))//数组a里面是生成的式子 { flag=0; break; } } return flag; } } class Suan4 { public String m; public Random random=new Random(); public Suan1 suan=new Suan1(); public String a; public int b,z; public int c; public String a1; public int panduan; public int x,y; public String daan; public int weizhi; public double kuohao() { panduan=suan.fanhuic(); if(panduan==3) { weizhi=a.indexOf("/"); if(weizhi==-1) { z=Integer.parseInt(a); return z; } else { x=Integer.parseInt(a.substring(0, weizhi)); y=Integer.parseInt(a.substring(weizhi+1)); return (Double.parseDouble(a.substring(0, weizhi))/Double.parseDouble(a.substring(weizhi+1))); } } else { z=Integer.parseInt(a); return z; } } public String shengcheng(int fanwei) { a1=suan.shengcheng(fanwei); a=suan.jisuan(); b=random.nextInt(fanwei); int c=random.nextInt(4); int daan1; String fuhao; int kuohao=random.nextInt(2); if(c==0)//0是加法 { fuhao="+"; } else if(c==1)//1是减法 { fuhao="-"; } else { fuhao="*"; } double daxiao=kuohao(); if(kuohao==0) { if(c==1&&daxiao<b) { m=String.valueOf(b)+fuhao+"("+a1+")"; if(weizhi!=-1&&panduan==3) { if(c==0) { int x1=b*y; int x2=x+x1; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } else if(c==1) { int x1=b*y; int x2=x1-x; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } else if(c==2) { int x2=x*b; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } } else { if(c==0) { daan=String.valueOf(b+z); } else if(c==1) { daan=String.valueOf(b-z); } else { daan=String.valueOf(b*z); } } } else { m="("+a1+")"+fuhao+String.valueOf(b); if(weizhi!=-1&&panduan==3) { if(c==0) { int x1=b*y; int x2=x+x1; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } else if(c==1) { int x1=b*y; int x2=x-x1; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } else if(c==2) { int x2=x*b; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } } else { if(c==0) { daan=String.valueOf(z+b); } else if(c==1) { daan=String.valueOf(z-b); } else { daan=String.valueOf(z*b); } } } } else { if(c==1&&daxiao>b) { m="("+a1+")"+fuhao+String.valueOf(b); if(weizhi!=-1&&panduan==3) { if(c==0) { int x1=b*y; int x2=x+x1; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } else if(c==1) { int x1=b*y; int x2=x-x1; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } else if(c==2) { int x2=x*b; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } } else { if(c==0) { daan=String.valueOf(z+b); } else if(c==1) { daan=String.valueOf(z-b); } else { daan=String.valueOf(z*b); } } } else { m=String.valueOf(b)+fuhao+"("+a1+")"; if(weizhi!=-1&&panduan==3) { if(c==0) { int x1=b*y; int x2=x+x1; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } else if(c==1) { int x1=b*y; int x2=x1-x; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } else if(c==2) { int x2=x*b; if(x2%y==0) { daan=String.valueOf(x2/y); } else { if(x2>y) { int shang=x2/y; int yushu=x2-y*shang; daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y); } else { daan=String.valueOf(x2)+"/"+String.valueOf(y); } } } } else { if(c==0) { daan=String.valueOf(b+z); } else if(c==1) { daan=String.valueOf(b-z); } else { daan=String.valueOf(b*z); } } } } m=m+"="; return m; } public int jianyan(String a[],int l)//检验是否重复的函数 { int flag=1; for(int i=0;i<l;i++) { if(m.equals(a[i])) { flag=0; break; } } return flag; } } int tishu; int fanwei; int m=0; String shuju[]=new String[10000]; int flag=0; Suan4 a=new Suan4(); String daan,daan1; String zhengque="",cuowu=""; %> <% tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei")))); session.setAttribute("tishu", tishu); if(m<tishu)//生成30个计算式 { shuju[m]=a.shengcheng(fanwei);//将生成的计算式储存咋数组里面 flag=a.jianyan(shuju, m);//返回是否有重复 if(flag==1)//如果没有就是1 { if(m+1==tishu) {daan=a.daan; session.setAttribute("shuju", shuju[m]); session.setAttribute("daan", daan); session.setAttribute("m", m); %> <form id="form2" name="form2" method="post" action="kuohaohuoqu.jsp"> <div style="text-align:center"> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <%out.print(m+1+"."+shuju[m]+"="); m=0;%> <br> <br> <br> <br> 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> <input name="" type="submit" value="提交" /> </div> </form> <% } else { daan=a.daan; session.setAttribute("shuju", shuju[m]); session.setAttribute("daan", daan); session.setAttribute("m", m); %> <form id="form2" name="form2" method="post" action="kuohaohuoqu.jsp"> <div style="text-align:center"> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <%out.print(m+1+"."+shuju[m]+"=");%> <br> <br> <br> <br> 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> <input name="" type="submit" value="下一个" /> </div> </form> <% m++; flag=0; } } else { response.setHeader("refresh","1;url = kuohao.jsp"); } } %> </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>Insert title here</title> </head> <body> <% try { int tishu=Integer.parseInt(request.getParameter("geshu")); int fanwei=Integer.parseInt(request.getParameter("fanwei")); session.setAttribute("tishu", tishu); session.setAttribute("fanwei", fanwei); response.setHeader("refresh","0;url = kuohao.jsp"); } catch(Exception e) { %> <script type="text/javascript"> alert("输入错误,点击确定返回重新输入!!!") </script> <% response.setHeader("refresh","0;url = kuohaoerror.jsp"); } %> </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>Insert title here</title> <style type="text/css"> body { background-image: url(image/7.jpg); } </style> </head> <body> <form id="form2" name="form2" method="post" action="kuohaochuangdi.jsp"> <div style="text-align:center;color:#F09"> <br> <br> <br> <br> <br> <br> 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> <input name="" type="submit" value="提交" /> </div> </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>Insert title here</title> <style type="text/css"> body { background-image: url(image/7.jpg); } </style> </head> <body> <form id="form2" name="form2" method="post" action="kuohaochuangdi.jsp"> <div style="text-align:center;color:#F09"> <br> <br> <br> <br> <br> <br> 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> <input name="" type="submit" value="提交" /> </div> </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>Insert title here</title> <style type="text/css"> body { background-image: url(image/7.jpg); } </style> </head> <body> <% String panduan=request.getParameter("xuanze"); if(panduan.equals("A")) { %> <form id="form2" name="form2" method="post" action="chaundi.jsp"> <div style="text-align:center;color:#F09"> <br> <br> <br> <br> <br> <br> 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> <input name="" type="submit" value="提交" /> </div> </form> <% } else if(panduan.equals("B")) { %> <br> <br> <br> <br> <br> <br> <form id="form3" name="form4" method="post" action="fenchuandi.jsp"> <div style="text-align:center;color:#F09"> 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> <input name="" type="submit" value="提交" /> </div> </form> <% } else if(panduan.equals("C")) { %> <form id="form2" name="form2" method="post" action="fenzhengchuangdi.jsp"> <div style="text-align:center;color:#F09"> <br> <br> <br> <br> <br> <br> 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> <input name="" type="submit" value="提交" /> </div> </form> <% } else if(panduan.equals("D")) { %> <form id="form2" name="form2" method="post" action="yushuchuangdi.jsp"> <div style="text-align:center;color:#F09"> <br> <br> <br> <br> <br> <br> 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> <input name="" type="submit" value="提交" /> </div> </form> <% } else if(panduan.equals("E")) { %> <form id="form2" name="form2" method="post" action="kuohaochuangdi.jsp"> <div style="text-align:center;color:#F09"> <br> <br> <br> <br> <br> <br> 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> <input name="" type="submit" value="提交" /> </div> </form> <% } else { %> <script type="text/javascript"> alert("输入错误,请点击确定重新输入!!!"); </script> <% response.setHeader("refresh","0;url = xuanze.html"); } %> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>主界面</title> <style type="text/css"> body { background-image: url(image/17.jpg); } </style> </head> <body> <div style="text-align: center; font-family: 微软雅黑; font-size: 50px; color: #C03; "><strong><em>四则运算</em></strong></div> <div style="text-align: center; font-family: 微软雅黑; font-size: 15px; color: #C03; "><strong><em>Welcome To User The System</em></strong></div> <br/> <div style="text-align: center; font-family: 微软雅黑; font-size: 20px;color: #C03;"><strong><em>请选择出题的范围</em></strong></div><br /> <form name="form1" method="post" action="panduan.jsp"> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <blockquote> <div style="color: #C03"> <p> <strong>A:整数的四则计算<br /> B:真分数的四则计算<br /> C:整数与真分数的混合四则运算<br /> D:有余数的除法<br /> E:有括号的四则运算<br /> </strong> </p> </div> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> </blockquote> <div style="text-align: center;color: #C03 "> <strong>请选择:</strong><input name="xuanze" type="text"/> <input name="" type="submit" value="提交" /> <input name="" type="reset" value="重置" /> </div> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.Random"%> <!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>Insert title here</title> <style type="text/css"> body { background-image: url(image/4.jpg); } </style> </head> <body> <%! class Suan3//有余数的类 { public int x,y;//定义两个变量 public String m; public Random random=new Random(); int fanwei; public String shengcheng(int fanwei1)//定义生成函数 { fanwei=fanwei1; x=random.nextInt(fanwei); y=random.nextInt(fanwei); for(int i=0;;i++) { if(y==0) { y=random.nextInt(fanwei); } else { break; } } m=String.valueOf(x)+"/"+String.valueOf(y);//返回计算式 return m; } public String shuchu()//生成输出函数 { String daan; int shang,yushu; shang=x/y; yushu=x-shang*y; daan=String.valueOf(shang)+"/"+String.valueOf(yushu);//返回计算结果 return daan; } public int jianyan(String a[],int l)//检验是否重复的函数 { int flag=1; for(int i=0;i<l;i++) { if(m.equals(a[i])) { flag=0; break; } } return flag; } } int tishu; int fanwei; int m=0; String shuju[]=new String[10000]; int flag=0; Suan3 a=new Suan3(); String daan,daan1; %> <% tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei")))); session.setAttribute("tishu", tishu); if(m<tishu) { shuju[m]=a.shengcheng(fanwei); flag=a.jianyan(shuju, m);//返回是否有重复 if(flag==1)//如果没有就是1 { if(m+1==tishu) {daan=a.shuchu(); session.setAttribute("shuju", shuju[m]); session.setAttribute("daan", daan); session.setAttribute("m", m); %> <form id="form2" name="form2" method="post" action="yushuhuoqu.jsp"> <div style="text-align:center"> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <%out.print(m+1+"."+shuju[m]+"="); m=0;%> <br> <br> <br> <br> 请输入商:<input name="daan1" type="text" value=""/><br /><br/> 请输入余数:<input name="daan2" type="text" value=""/><br> <br> <input name="" type="submit" value="提交" /> </div> </form> <% } else { daan=a.shuchu(); session.setAttribute("shuju", shuju[m]); session.setAttribute("daan", daan); session.setAttribute("m", m); %> <form id="form2" name="form2" method="post" action="yushuhuoqu.jsp"> <div style="text-align:center"> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <%out.print(m+1+"."+shuju[m]+"=");%> <br> <br> <br> <br> 请输入商:<input name="daan1" type="text" value=""/><br /><br/> 请输入余数:<input name="daan2" type="text" value=""/><br> <br> <input name="" type="submit" value="下一个" /> </div> </form> <% m++; flag=0; } } else { response.setHeader("refresh","0;url = yushu.jsp"); } } %> </body> </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 </head> 9 <body> 10 <% 11 try 12 { 13 int tishu=Integer.parseInt(request.getParameter("geshu")); 14 int fanwei=Integer.parseInt(request.getParameter("fanwei")); 15 session.setAttribute("tishu", tishu); 16 session.setAttribute("fanwei", fanwei); 17 response.setHeader("refresh","0;url = yushu.jsp"); 18 } 19 catch(Exception e) 20 { 21 %> 22 <script type="text/javascript"> 23 alert("输入错误,点击确定返回重新输入!!!") 24 </script> 25 <% 26 response.setHeader("refresh","0;url = yushuerror.jsp"); 27 } 28 %> 29 </body> 30 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 <style type="text/css"> 9 body 10 { 11 background-image: url(image/7.jpg); 12 } 13 </style> 14 </head> 15 <body> 16 <form id="form2" name="form2" method="post" action="yushuchuangdi.jsp"> 17 <div style="text-align:center;color:#F09"> 18 <br> 19 <br> 20 <br> 21 <br> 22 <br> 23 <br> 24 请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/> 25 请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/> 26 <input name="" type="submit" value="提交" /> 27 </div> 28 </form> 29 </body> 30 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 <style type="text/css"> 9 body 10 { 11 background-image: url(image/18.jpg); 12 } 13 </style> 14 </head> 15 <body> 16 <%! 17 int tishu1; 18 String error="",zhengque=""; 19 %> 20 <% 21 try 22 { 23 Connection con = null; //定义一个MYSQL链接对象 24 Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动 25 con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL 26 java.sql.Statement stmt; //创建声明 27 stmt = con.createStatement(); 28 String shuju=String.valueOf(session.getAttribute("shuju")); 29 String daan=String.valueOf(session.getAttribute("daan")); 30 int weizhi=daan.indexOf('/'); 31 String shang1=daan.substring(0, weizhi); 32 String yushu1=daan.substring(weizhi+1); 33 int m=Integer.parseInt(String.valueOf(session.getAttribute("m"))); 34 tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); 35 String shang =request.getParameter("daan1"); 36 String yushu =request.getParameter("daan2"); 37 String sql="INSERT INTO 有余数的除法 (shizi,shang,yushu,usershang,useryushu) VALUES ('"+shuju+" = "+"','"+shang1+"','"+yushu1+"','"+shang+"','"+yushu+"')"; 38 stmt.executeUpdate(sql); 39 if(daan.equals(shang+"/"+yushu)) 40 { 41 zhengque=zhengque+String.valueOf(m+1)+","; 42 } 43 else 44 { 45 error=error+String.valueOf(m+1)+","; 46 } 47 if(m+1==tishu1) 48 { 49 sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')"; 50 stmt.executeUpdate(sql); 51 52 %> 53 <form id="form2" name="form2" method="post" action="xuanze.html"> 54 <div style="text-align:center;color:#F00"> 55 <strong> 56 <br> 57 <br> 58 <br> 59 <br> 60 <br> 61 <br> 62 <br> 63 <br> 64 <br> 65 <br> 66 <br> 67 <br> 68 <br> 69 <br> 70 <% 71 out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); 72 zhengque=""; 73 error=""; %> 74 <input name="" type="submit" value="确定" /> 75 </strong> 76 </div> 77 </form> 78 <% 79 } 80 else 81 { 82 response.setHeader("refresh","0;url = yushu.jsp"); 83 } 84 } 85 catch (Exception e) 86 { 87 System.out.print("MYSQL ERROR:" + e.getMessage()); 88 } 89 %> 90 </body> 91 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8" import="java.util.Random" import="java.sql.Connection" import="java.sql.DriverManager"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 <html> 5 <head> 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 7 <title>Insert title here</title> 8 <style type="text/css"> 9 body 10 { 11 background-image: url(image/4.jpg); 12 } 13 </style> 14 </head> 15 <body> 16 <%! 17 class Suan1//生成整数计算的类 18 { 19 public int x,y,c;//定义两个变量,还有一个符号变量 20 public Random random=new Random();//定义随机数 21 String m;//生成的计算式储存咋m里面 22 int fanwei; 23 public String shengcheng(int fanwei1)//自动生成数的函数 24 { 25 fanwei=fanwei1; 26 c=random.nextInt(4);//生成符号 27 String fuhao; 28 x=random.nextInt(fanwei);//生成100以内的自然数 29 y=random.nextInt(fanwei); 30 if(c==0)//0是加法 31 { 32 fuhao="+"; 33 m=String.valueOf(x)+fuhao+String.valueOf(y); 34 35 } 36 else if(c==1)//1是减法 37 { 38 fuhao="-"; 39 if(x>=y) 40 { 41 m=String.valueOf(x)+fuhao+String.valueOf(y); 42 } 43 else 44 { 45 m=String.valueOf(y)+fuhao+String.valueOf(x); 46 } 47 } 48 else if(c==2) 49 { 50 fuhao="*"; 51 m=String.valueOf(x)+fuhao+String.valueOf(y); 52 } 53 else 54 { 55 fuhao="/"; 56 for(int i=0;;i++) 57 { 58 if(y==0) 59 { 60 y=random.nextInt(fanwei); 61 } 62 else 63 { 64 break; 65 } 66 } 67 m=String.valueOf(x)+fuhao+String.valueOf(y); 68 } 69 return m; 70 71 } 72 public String shuchu()//定义输出函数 73 { 74 if(c==0) 75 { 76 return (String.valueOf(x+y));//并且返回计算的结果 77 } 78 else if(c==1) 79 { 80 if(x>=y)//将较大的数放在前面,不能出现负数 81 { 82 return (String.valueOf(x-y)); 83 } 84 else 85 { 86 return (String.valueOf(y-x)); 87 } 88 } 89 else if(c==2) 90 { 91 return (String.valueOf(x*y)); 92 } 93 else 94 { 95 if(x%y==0) 96 { 97 return (String.valueOf(x/y)); 98 } 99 else 100 { 101 if(x>y) 102 { 103 int shang=x/y; 104 int yushu=x-y*shang; 105 return (String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y)); 106 } 107 else 108 { 109 return (String.valueOf(x)+"/"+String.valueOf(y)); 110 } 111 } 112 } 113 } 114 public int fanhuic() 115 { 116 return c; 117 } 118 public int jianyan(String a[],int s)//检验是否有重复的式子,如果有返回0,没有就返回1 119 { 120 int flag=1; 121 for(int i=0;i<s;i++) 122 { 123 if(m.equals(a[i]))//数组a里面是生成的式子 124 { 125 flag=0; 126 break; 127 } 128 } 129 return flag; 130 } 131 } 132 int tishu; 133 int fanwei; 134 int m=0; 135 String shuju[]=new String[10000]; 136 int flag=0; 137 Suan1 a=new Suan1(); 138 String daan,daan1; 139 String zhengque="",cuowu=""; 140 %> 141 <% 142 tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu")))); 143 fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei")))); 144 session.setAttribute("tishu", tishu); 145 if(m<tishu)//生成30个计算式 146 { 147 shuju[m]=a.shengcheng(fanwei);//将生成的计算式储存咋数组里面 148 flag=a.jianyan(shuju, m);//返回是否有重复 149 if(flag==1)//如果没有就是1 150 { 151 if(m+1==tishu) 152 {daan=a.shuchu(); 153 session.setAttribute("shuju", shuju[m]); 154 session.setAttribute("daan", daan); 155 session.setAttribute("m", m); 156 %> 157 <form id="form2" name="form2" method="post" action="huoqu.jsp"> 158 <div style="text-align:center"> 159 <br> 160 <br> 161 <br> 162 <br> 163 <br> 164 <br> 165 <br> 166 <br> 167 <br> 168 <br> 169 <br> 170 <br> 171 <br> 172 <%out.print(m+1+"."+shuju[m]+"="); 173 m=0;%> 174 <br> 175 <br> 176 <br> 177 <br> 178 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> 179 <input name="" type="submit" value="提交" /> 180 </div> 181 </form> 182 <% 183 } 184 else 185 { 186 daan=a.shuchu(); 187 session.setAttribute("shuju", shuju[m]); 188 session.setAttribute("daan", daan); 189 session.setAttribute("m", m); 190 %> 191 <form id="form2" name="form2" method="post" action="huoqu.jsp"> 192 <div style="text-align:center"> 193 <br> 194 <br> 195 <br> 196 <br> 197 <br> 198 <br> 199 <br> 200 <br> 201 <br> 202 <br> 203 <br> 204 <br> 205 <br> 206 <%out.print(m+1+"."+shuju[m]+"=");%> 207 <br> 208 <br> 209 <br> 210 <br> 211 请输入答案:<input name="daan1" type="text" value=""/><br /><br/> 212 <input name="" type="submit" value="下一个" /> 213 </div> 214 </form> 215 <% 216 m++; 217 flag=0; 218 } 219 220 } 221 else 222 { 223 response.setHeader("refresh","1;url = zhengshu.jsp"); 224 } 225 } 226 %> 227 228 229 </body> 230 </html>