zoukankan      html  css  js  c++  java
  • 简易计算器

    <%@ page language="java" contentType="text/html; charset=utf-8"%>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Calculator</title>
    </head>
    <body>
    <%!String result = ""; %>
    <%
    result = "计算结果:";
    String first =request.getParameter("first");
    String second = request.getParameter("second");
    String select = request.getParameter("select");
    if(first != null && first.length()!= 0 && second != null && second.length() != 0){
    if(select.equals("add")){
    result += Double.parseDouble(first) + "+" +Double.parseDouble(second)+"="+(Double.parseDouble(first)+Double.parseDouble(second));
    }else if(select.equals("minus")){
    result += Double.parseDouble(first) + "-" +Double.parseDouble(second)+"="+(Double.parseDouble(first)-Double.parseDouble(second));
    }else if(select.equals("multiply")){
    result += Double.parseDouble(first) + "*" +Double.parseDouble(second)+"="+(Double.parseDouble(first)*Double.parseDouble(second));
    }else if(select.equals("divide")){
    result += Double.parseDouble(first) + "÷" +Double.parseDouble(second)+"="+(Double.parseDouble(first)/Double.parseDouble(second));
    }
    }
    %>
    <form action="Calculator.jsp" method="post">
    <hr>
    <%=result%>
    <%
    result= "计算结果:";
    %>
    <hr>
    <table border="1">
    <tr>
    <td colspan="2">简单的计算器</td>
    </tr>
    <tr>
    <td>第一个操作数</td>
    <td><input type="text" name="first"></td>
    </tr>
    <tr>
    <td>操作符</td>
    <td>
    <select name="select">
    <option value="add">+</option>
    <option value="minus">-</option>
    <option value="multiply">*</option>
    <option value="divide">/</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>第二个操作数</td>
    <td><input type="text" name="second"></td>
    </tr>
    <tr>
    <td colspan="2"><input type="submit" value="计算"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  • 相关阅读:
    ASP.NET中常用的优化性能的方法
    把WinDbg集成到Visual Studio中
    提高ASP.net的性能
    Msn Library
    [转帖]OutOfMemoryException问题的处理
    一完美的关于请求的目录不存在而需要url重写的解决方案!
    在 ASP.NET 中执行 URL 重写
    转 内存不断上升处理方法
    IIS 6 通配符应用映射和HttpHandler配置
    Java开源
  • 原文地址:https://www.cnblogs.com/tcc89/p/5599013.html
Copyright © 2011-2022 走看看