日期:2014-05-20 浏览次数:20663 次
<%@page contentType="text/html;charset=gb2312"%> <html> <body> <h1> 我的简易计算器 </h1> <form name="form1" action="???"> 请输入第一个数: <br> <input type="text" name="num1"> <br> 请选择运算符号: <br> <select name="flag"> <option value=+> + </option> <option value=-> - </option> <option value=*> * </option> <option value= /> / </option> </select> <br> 请输入第二个数: <br> <input type="text" name="num2"> <br> <input type="submit" value="计算"> </form> <% String snum1 = request.getParameter("num1"); String snum2 = request.getParameter("num2"); String flag = request.getParameter("flag"); int num1 = 0; int num2 = 0; int result = 0; num1 = Integer.parseInt(snum1); num2 = Integer.parseInt(snum2); if (flag.equals("+")) { result = num1 + num2; } else if (flag.equals("-")) { result = num1 - num2; } else if (flag.equals("*")) { result = num1 * num2; } else { result = num1 / num2; } out.print(result); %> </body> </html>