• 简易计算器


    <%@ 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>

  • 相关阅读:
    js动态获取地址栏后的参数
    html页面保存数的两种方式
    微信开发之八 页面获取周围beacon设备
    【摄影】田子坊
    最好的时光在路上,最美的风景在远方
    【前端统计图】echarts实现简单柱状图
    js实现计时功能
    luogu 电车
    cogs luogu 砍树
    cogs 通往奥格瑞玛的道路 WD
  • 原文地址:https://www.cnblogs.com/tcc89/p/5599013.html
Copyright © 2020-2023  润新知