小学四年级水平的四则运算--网页版

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here




请输入题目数量

此页面用于输入题目数量,结果:

小学四年级水平的四则运算--网页版_第1张图片

 

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here

<% //Integer.parseInt(str); 获取题目数量 int n = Integer.parseInt(request.getParameter("quantity")); //out.print(n); int a; int b; //int n=50; String operator = ""; String[] expression = new String[n]; int[] result = new int[n]; int[] user = new int[n]; //1.随机数 2.符号 3.是否可以生成表达式---满足输出以及储存结果 不满足重新生成随机数和表达式 int i = 0; // for (i = 0; i < n; ) while (i < n) { //生成一个表达式 a = (int) (1 + Math.random() * 99); b = (int) (1 + Math.random() * 99); int k = (int) (1 + Math.random() * 3);//1~4对应不同的运算符 switch (k) { case 1: operator = "+"; break; case 2: operator = "-"; break; case 3: operator = "*"; break; case 4: operator = "/"; break; } //判断表达式是否满足要求 if (operator.equals("+") && a + b < 100) { result[i] = a + b; out.print(i+1+"."+a + operator + b + "=" + "
"); %> >
<% i++; } //out.print(expression[i]); else if (operator.equals("-") && a - b >= 0) { result[i] = a - b; out.print(i+1+"."+a + operator + b + "=" + "
"); %> >
<% i++; } else if (operator.equals("*") && a * b <= 100) { result[i] = a * b; out.print(i+1+"."+a + operator + b + "=" + "
"); %> >
<% i++; } else if (operator.equals("/") && (a % b == 0) && b != 0) { result[i] = a / b; out.print(i+1+"."+a + operator + b + "=" + "
"); %> >
<% i++; } %> <%-- --%> <% }; %> <% //session.setAttribute("useras", user); session.setAttribute("crctas", result); session.setAttribute("num",n); %>

此页面用于出题:

小学四年级水平的四则运算--网页版_第2张图片

 

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here


    
<% //int[] user = (int[]) session.getAttribute("useras"); int[] result = (int[]) session.getAttribute("crctas"); int n = (Integer) session.getAttribute("num"); int []user=new int[n]; int count = 0; for(int i=0;i) { int a=Integer.parseInt(request.getParameter("user"+i)); user[i]=a; } for (int i = 0; i < n; i++) { if (user[i] == result[i]) { out.print("第" + (i + 1 )+ "题回答正确 "); count++; } else out.print("第" + (i + 1) + "题回答错误 ,正确答案是:" + result[i]); out.println("
"); } out.print("总共做对 " + count + "道题,错了 "+(n-count)+"道题"); %>

此页面显示判断结果:

小学四年级水平的四则运算--网页版_第3张图片

 

 

 

总结:

当时有些功能不知道怎么实现,在某位好心人的帮助下,这些雪中送炭的代码摘录下来在这里了哦

 
   >



<% //session.setAttribute("useras", user); session.setAttribute("crctas", result); session.setAttribute("num",n); %>
          int[] result = (int[]) session.getAttribute("crctas"); int n = (Integer) session.getAttribute("num");
 
 

 

 
 

 

你可能感兴趣的:(小学四年级水平的四则运算--网页版)