zoukankan      html  css  js  c++  java
  • Web四则运算

    代码(1):

    <%@ 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=ISO-8859-1">
    <title>四则运算</title>
    </head>
    <body>
    <h1>四则运算</h1>
    <form action="yunsuan.jsp" method="post">
    出题页数:<input type="text" name = "shuliang"><br>
    <h2>1.整数运算 2.真分数运算</h2>
    题目样式<input type="text" name="choose"><br>
    <input type="submit" value="提交">
    </form>
    </body>
    </html>

    代码(2):

    <%@ 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>
    <%
    JspWriter mout=pageContext.getOut();
    String zh = request.getParameter("shuliang");
    String zhh = request.getParameter("choose");
    int x=Integer.parseInt(zh);
    int y=Integer.parseInt(zhh);
    int m,n,j;
    char []ch=new char[4];
    ch[0]='+';
    ch[1]='-';
    ch[2]='*';
    ch[3]='/';
    if(y==1)
    {
    for(int ii=1;ii<=x;ii++)
    {
    mout.print("30道题目");
    mout.print("<br>");
    String []A=new String[30];
    for(int i=0;i<30;i++)
    {
    m=(int)(Math.random()*10+1);
    n=(int)(Math.random()*10+1);
    j=(int)(Math.random()*4+1);
    A[i]=m+" "+ch[j-1]+" "+n+"=";
    for(int k=i+1;k<30;k++)
    {
    if(A[i].equals(A[k]))
    {
    m=(int)(Math.random()*10+1);
    n=(int)(Math.random()*10+1);
    j=(int)(Math.random()*4+1);
    A[k]=m+" "+ch[j-1]+" "+n+"=";
    k--;
    }
    }
    mout.print((i+1)+". "+A[i]);
    mout.print("<br>");
    }
    mout.print("-"+ii+"-");
    mout.print("<br><br><br>");
    }
    }
    if(y==2)
    {
    for(int ii=1;ii<=x;ii++)
    {
    int a,b,c,d;
    String aa,bb;
    mout.print("30道题目");
    mout.print("<br>");
    String []B=new String[30];
    for(int i=0;i<30;i++)
    {
    a=(int)(Math.random()*100+1);
    b=(int)(Math.random()*100+1);
    if(a>b)
    aa=b+"/"+a;
    else if(a<b)
    aa=a+"/"+b;
    else
    aa="1";
    c=(int)(Math.random()*100+1);
    d=(int)(Math.random()*100+1);
    if(c>d)
    bb=d+"/"+c;
    else if(c<d)
    bb=c+"/"+d;
    else
    bb="1";
    j=(int)(Math.random()*4+1);
    B[i]=aa+" "+ch[j-1]+" "+bb+"=";
    for(int k=i+1;k<30;k++)
    {
    if(B[i].equals(B[k]))
    {
    m=(int)(Math.random()*10+1);
    n=(int)(Math.random()*10+1);
    j=(int)(Math.random()*4+1);
    B[k]=aa+" "+ch[j-1]+" "+bb+"=";
    k--;
    }
    }
    mout.print((i+1)+". "+B[i]);
    mout.print("<br>");
    }
    mout.print("-"+ii+"-");
    mout.print("<br><br><br>");
    }
    }
    %>
    </body>
    </html>

    结果截图:

  • 相关阅读:
    SpringMVC 工作流程
    zookeeper
    Zookeeper
    HashMap
    Shiro learning
    Shiro learning
    Shiro learning
    Easy Poi入门
    Enum枚举学习- java5之前和之后的写法
    linux命令行todo列表管理工具Taskwarrior介绍
  • 原文地址:https://www.cnblogs.com/jokerr/p/6492197.html
Copyright © 2011-2022 走看看