add, subtract, multiply, divide, clear
This commit is contained in:
Binary file not shown.
@ -11,6 +11,40 @@ public class _calculator__jsp extends com.caucho.jsp.JavaPage
|
|||||||
{
|
{
|
||||||
private static final java.util.HashMap<String,java.lang.reflect.Method> _jsp_functionMap = new java.util.HashMap<String,java.lang.reflect.Method>();
|
private static final java.util.HashMap<String,java.lang.reflect.Method> _jsp_functionMap = new java.util.HashMap<String,java.lang.reflect.Method>();
|
||||||
private boolean _caucho_isDead;
|
private boolean _caucho_isDead;
|
||||||
|
|
||||||
|
|
||||||
|
// \u5b58\u904b\u7b97\u5143\u7684\u503c
|
||||||
|
float[] number = {0, 0};
|
||||||
|
// \u5728\u7b2c\u5e7e\u500b\u904b\u7b97\u5143
|
||||||
|
int i = 0;
|
||||||
|
// \u4f7f\u7528\u4e2d\u7684\u904b\u7b97\u5b50
|
||||||
|
int oprator = 0;
|
||||||
|
// \u52a0\u6cd5
|
||||||
|
void add() {
|
||||||
|
number[0] += number[1];
|
||||||
|
}
|
||||||
|
// \u6e1b\u6cd5
|
||||||
|
void subtract() {
|
||||||
|
number[0] -= number[1];
|
||||||
|
}
|
||||||
|
// \u4e58\u6cd5
|
||||||
|
void multiply() {
|
||||||
|
number[0] *= number[1];
|
||||||
|
}
|
||||||
|
// \u9664\u6cd5
|
||||||
|
void divide() {
|
||||||
|
number[0] /= number[1];
|
||||||
|
}
|
||||||
|
// \u53d6\u9918
|
||||||
|
void remainder() {
|
||||||
|
number[0] %= number[1];
|
||||||
|
}
|
||||||
|
//\u6e05\u9664
|
||||||
|
void clear() {
|
||||||
|
number[0] = 0;
|
||||||
|
number[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void
|
public void
|
||||||
_jspService(javax.servlet.http.HttpServletRequest request,
|
_jspService(javax.servlet.http.HttpServletRequest request,
|
||||||
@ -26,35 +60,99 @@ public class _calculator__jsp extends com.caucho.jsp.JavaPage
|
|||||||
final javax.el.ELContext _jsp_env = pageContext.getELContext();
|
final javax.el.ELContext _jsp_env = pageContext.getELContext();
|
||||||
javax.servlet.ServletConfig config = getServletConfig();
|
javax.servlet.ServletConfig config = getServletConfig();
|
||||||
javax.servlet.Servlet page = this;
|
javax.servlet.Servlet page = this;
|
||||||
response.setContentType("text/html; charset=big5");
|
response.setContentType("text/html; charset=utf-8");
|
||||||
request.setCharacterEncoding("Big5");
|
request.setCharacterEncoding("UTF-8");
|
||||||
try {
|
try {
|
||||||
out.write(_jsp_string0, 0, _jsp_string0.length);
|
out.write(_jsp_string0, 0, _jsp_string0.length);
|
||||||
|
|
||||||
String inputdata = request.getParameter("symbol");
|
// \u8f38\u5165\u7684\u5b57\u5143
|
||||||
|
|
||||||
if(inputdata == null) {
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
String inputdata = request.getParameter("symbol");
|
||||||
|
if(inputdata == null) {
|
||||||
|
inputdata = "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputdata.equals("CE")) {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
// \u5982\u679c\u662f\u6578\u5b57\u5c31\u7d2f\u7a4d\u8f38\u5165
|
||||||
|
else if (inputdata.equals("0") ||
|
||||||
|
inputdata.equals("1") ||
|
||||||
|
inputdata.equals("2") ||
|
||||||
|
inputdata.equals("3") ||
|
||||||
|
inputdata.equals("4") ||
|
||||||
|
inputdata.equals("5") ||
|
||||||
|
inputdata.equals("6") ||
|
||||||
|
inputdata.equals("7") ||
|
||||||
|
inputdata.equals("8") ||
|
||||||
|
inputdata.equals("9")) {
|
||||||
|
// \u8f38\u5165\u591a\u4f4d\u6578\u5b57
|
||||||
|
number[i] *= 10;
|
||||||
|
number[i] += Float.parseFloat(inputdata);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// \u5982\u679c\u6709\u9078\u64c7\u7684\u904b\u7b97\u5b50
|
||||||
|
if (oprator != 0) {
|
||||||
|
switch (oprator) {
|
||||||
|
case 1:
|
||||||
|
add();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
subtract();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
multiply();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
divide();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
remainder();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inputdata.equals("=")) {
|
||||||
|
// \u6e05\u9664\u904b\u7b97\u5b50
|
||||||
|
oprator = 0;
|
||||||
|
// \u56de\u5230\u7b2c\u4e00\u500b\u904b\u7b97\u5143
|
||||||
|
i = 0;
|
||||||
|
number[1] = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// \u56de\u5230\u7b2c\u4e8c\u500b\u904b\u7b97\u5143
|
||||||
|
i = 1;
|
||||||
|
number[1] = 0;
|
||||||
|
// \u628a\u904b\u7b97
|
||||||
|
if (inputdata.equals("+")) {
|
||||||
|
oprator = 1;
|
||||||
|
}
|
||||||
|
else if (inputdata.equals("-")) {
|
||||||
|
oprator = 2;
|
||||||
|
}
|
||||||
|
else if (inputdata.equals("*")) {
|
||||||
|
oprator = 3;
|
||||||
|
}
|
||||||
|
else if (inputdata.equals("/")) {
|
||||||
|
oprator = 4;
|
||||||
|
}
|
||||||
|
else if (inputdata.equals("%")) {
|
||||||
|
oprator = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// \u5370\u51fa\u73fe\u5728\u7684\u6578\u5b57
|
||||||
|
out.println(number[i]);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
// \u932f\u8aa4\u8a0a\u606f
|
||||||
|
throw new NumberFormatException("\u60a8\u8f38\u5165\u7684\u4e0d\u662f\u6574\u6578");
|
||||||
|
}
|
||||||
|
|
||||||
out.write(_jsp_string1, 0, _jsp_string1.length);
|
out.write(_jsp_string1, 0, _jsp_string1.length);
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
try{
|
|
||||||
//int data = Integer.parseInt(inputdata);
|
|
||||||
out.println(inputdata);
|
|
||||||
|
|
||||||
out.write(_jsp_string2, 0, _jsp_string2.length);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(NumberFormatException e) {
|
|
||||||
throw new NumberFormatException("\ufffd\u523b\u6493\ufffd\u4ea6\ufffd\ufffd\u929d\ufffd\ufffd\u8200\ufffd\u6e54\ufffd\ufffd");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
out.write(_jsp_string3, 0, _jsp_string3.length);
|
|
||||||
} catch (java.lang.Throwable _jsp_e) {
|
} catch (java.lang.Throwable _jsp_e) {
|
||||||
pageContext.handlePageException(_jsp_e);
|
pageContext.handlePageException(_jsp_e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -128,18 +226,14 @@ public class _calculator__jsp extends com.caucho.jsp.JavaPage
|
|||||||
String resourcePath = loader.getResourcePathSpecificFirst();
|
String resourcePath = loader.getResourcePathSpecificFirst();
|
||||||
mergePath.addClassPath(resourcePath);
|
mergePath.addClassPath(resourcePath);
|
||||||
com.caucho.vfs.Depend depend;
|
com.caucho.vfs.Depend depend;
|
||||||
depend = new com.caucho.vfs.Depend(appDir.lookup("calculator.jsp"), 3495430881658896476L, false);
|
depend = new com.caucho.vfs.Depend(appDir.lookup("calculator.jsp"), 7283550880123519635L, false);
|
||||||
com.caucho.jsp.JavaPage.addDepend(_caucho_depends, depend);
|
com.caucho.jsp.JavaPage.addDepend(_caucho_depends, depend);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static char []_jsp_string0;
|
|
||||||
private final static char []_jsp_string1;
|
private final static char []_jsp_string1;
|
||||||
private final static char []_jsp_string3;
|
private final static char []_jsp_string0;
|
||||||
private final static char []_jsp_string2;
|
|
||||||
static {
|
static {
|
||||||
_jsp_string0 = "\n<html>\n <head>\n <title> Calculator </title>\n </head>\n\n <body>\n <p>Calculator</p>\n ".toCharArray();
|
_jsp_string1 = " \n </body>\n</html>".toCharArray();
|
||||||
_jsp_string1 = "\n\n <form action=\"calculator.jsp\" method=post>\n <p>\n <input name=\"display\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"%\">\n <input name=\"symbol\" type=\"submit\" value=\"root\">\n <input name=\"symbol\" type=\"submit\" value=\"square\">\n <input name=\"symbol\" type=\"submit\" value=\"reciprocal\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"CE\">\n <input name=\"symbol\" type=\"submit\" value=\"C\">\n <input name=\"symbol\" type=\"submit\" value=\"X\">\n <input name=\"symbol\" type=\"submit\" value=\"/\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"7\">\n <input name=\"symbol\" type=\"submit\" value=\"8\">\n <input name=\"symbol\" type=\"submit\" value=\"9\">\n <input name=\"symbol\" type=\"submit\" value=\"*\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"4\">\n <input name=\"symbol\" type=\"submit\" value=\"5\">\n <input name=\"symbol\" type=\"submit\" value=\"6\">\n <input name=\"symbol\" type=\"submit\" value=\"-\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"1\">\n <input name=\"symbol\" type=\"submit\" value=\"2\">\n <input name=\"symbol\" type=\"submit\" value=\"3\">\n <input name=\"symbol\" type=\"submit\" value=\"+\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"+-\">\n <input name=\"symbol\" type=\"submit\" value=\"0\">\n <input name=\"symbol\" type=\"submit\" value=\".\">\n <input name=\"symbol\" type=\"submit\" value=\"=\">\n </p> \n </form>\n\n ".toCharArray();
|
_jsp_string0 = "\n<html>\n <head>\n <title> Calculator </title>\n </head>\n\n <body>\n <p>Calculator</p>\n \n \n <form action=\"calculator.jsp\" method=post>\n <p>\n <input name=\"symbol\" type=\"submit\" value=\"%\">\n <input name=\"symbol\" type=\"submit\" value=\"root\">\n <input name=\"symbol\" type=\"submit\" value=\"square\">\n <input name=\"symbol\" type=\"submit\" value=\"reciprocal\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"CE\">\n <input name=\"symbol\" type=\"submit\" value=\"C\">\n <input name=\"symbol\" type=\"submit\" value=\"X\">\n <input name=\"symbol\" type=\"submit\" value=\"/\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"7\">\n <input name=\"symbol\" type=\"submit\" value=\"8\">\n <input name=\"symbol\" type=\"submit\" value=\"9\">\n <input name=\"symbol\" type=\"submit\" value=\"*\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"4\">\n <input name=\"symbol\" type=\"submit\" value=\"5\">\n <input name=\"symbol\" type=\"submit\" value=\"6\">\n <input name=\"symbol\" type=\"submit\" value=\"-\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"1\">\n <input name=\"symbol\" type=\"submit\" value=\"2\">\n <input name=\"symbol\" type=\"submit\" value=\"3\">\n <input name=\"symbol\" type=\"submit\" value=\"+\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"+-\">\n <input name=\"symbol\" type=\"submit\" value=\"0\">\n <input name=\"symbol\" type=\"submit\" value=\".\">\n <input name=\"symbol\" type=\"submit\" value=\"=\">\n </p> \n </form>\n\n ".toCharArray();
|
||||||
_jsp_string3 = " \n </body>\n</html>".toCharArray();
|
|
||||||
_jsp_string2 = "\n <form action=\"calculator.jsp\" method=post>\n <p>\n <input name=\"display\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"%\">\n <input name=\"symbol\" type=\"submit\" value=\"root\">\n <input name=\"symbol\" type=\"submit\" value=\"square\">\n <input name=\"symbol\" type=\"submit\" value=\"reciprocal\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"CE\">\n <input name=\"symbol\" type=\"submit\" value=\"C\">\n <input name=\"symbol\" type=\"submit\" value=\"X\">\n <input name=\"symbol\" type=\"submit\" value=\"/\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"7\">\n <input name=\"symbol\" type=\"submit\" value=\"8\">\n <input name=\"symbol\" type=\"submit\" value=\"9\">\n <input name=\"symbol\" type=\"submit\" value=\"*\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"4\">\n <input name=\"symbol\" type=\"submit\" value=\"5\">\n <input name=\"symbol\" type=\"submit\" value=\"6\">\n <input name=\"symbol\" type=\"submit\" value=\"-\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"1\">\n <input name=\"symbol\" type=\"submit\" value=\"2\">\n <input name=\"symbol\" type=\"submit\" value=\"3\">\n <input name=\"symbol\" type=\"submit\" value=\"+\">\n <br>\n <input name=\"symbol\" type=\"submit\" value=\"+-\">\n <input name=\"symbol\" type=\"submit\" value=\"0\">\n <input name=\"symbol\" type=\"submit\" value=\".\">\n <input name=\"symbol\" type=\"submit\" value=\"=\">\n </p> \n </form>\n ".toCharArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,10 @@ JSP
|
|||||||
+ 1 calculator.jsp
|
+ 1 calculator.jsp
|
||||||
calculator.jsp
|
calculator.jsp
|
||||||
*L
|
*L
|
||||||
1#1:32
|
9#1,33:15
|
||||||
9#1,6:33
|
41#1:48,19
|
||||||
14#1:39
|
1#1:66
|
||||||
52#1,8:40
|
77#1,88:67
|
||||||
59#1:48
|
164#1:155
|
||||||
95#1,8:49
|
166#1:156
|
||||||
102#1:57
|
|
||||||
104#1:58
|
|
||||||
*E
|
*E
|
||||||
|
246
calculator.jsp
246
calculator.jsp
@ -1,4 +1,4 @@
|
|||||||
<%@ page contentType="text/html; charset=big5" %>
|
<%@ page contentType="text/html; charset=utf-8" %>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title> Calculator </title>
|
<title> Calculator </title>
|
||||||
@ -6,99 +6,161 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<p>Calculator</p>
|
<p>Calculator</p>
|
||||||
<%
|
<%!
|
||||||
String inputdata = request.getParameter("symbol");
|
// 存運算元的值
|
||||||
|
float[] number = {0, 0};
|
||||||
if(inputdata == null) {
|
// 在第幾個運算元
|
||||||
|
int i = 0;
|
||||||
%>
|
// 使用中的運算子
|
||||||
|
int oprator = 0;
|
||||||
<form action="calculator.jsp" method=post>
|
// 加法
|
||||||
<p>
|
void add() {
|
||||||
<input name="display">
|
number[0] += number[1];
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="%">
|
|
||||||
<input name="symbol" type="submit" value="root">
|
|
||||||
<input name="symbol" type="submit" value="square">
|
|
||||||
<input name="symbol" type="submit" value="reciprocal">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="CE">
|
|
||||||
<input name="symbol" type="submit" value="C">
|
|
||||||
<input name="symbol" type="submit" value="X">
|
|
||||||
<input name="symbol" type="submit" value="/">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="7">
|
|
||||||
<input name="symbol" type="submit" value="8">
|
|
||||||
<input name="symbol" type="submit" value="9">
|
|
||||||
<input name="symbol" type="submit" value="*">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="4">
|
|
||||||
<input name="symbol" type="submit" value="5">
|
|
||||||
<input name="symbol" type="submit" value="6">
|
|
||||||
<input name="symbol" type="submit" value="-">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="1">
|
|
||||||
<input name="symbol" type="submit" value="2">
|
|
||||||
<input name="symbol" type="submit" value="3">
|
|
||||||
<input name="symbol" type="submit" value="+">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="+-">
|
|
||||||
<input name="symbol" type="submit" value="0">
|
|
||||||
<input name="symbol" type="submit" value=".">
|
|
||||||
<input name="symbol" type="submit" value="=">
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<%
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
try{
|
|
||||||
//int data = Integer.parseInt(inputdata);
|
|
||||||
out.println(inputdata);
|
|
||||||
%>
|
|
||||||
<form action="calculator.jsp" method=post>
|
|
||||||
<p>
|
|
||||||
<input name="display">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="%">
|
|
||||||
<input name="symbol" type="submit" value="root">
|
|
||||||
<input name="symbol" type="submit" value="square">
|
|
||||||
<input name="symbol" type="submit" value="reciprocal">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="CE">
|
|
||||||
<input name="symbol" type="submit" value="C">
|
|
||||||
<input name="symbol" type="submit" value="X">
|
|
||||||
<input name="symbol" type="submit" value="/">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="7">
|
|
||||||
<input name="symbol" type="submit" value="8">
|
|
||||||
<input name="symbol" type="submit" value="9">
|
|
||||||
<input name="symbol" type="submit" value="*">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="4">
|
|
||||||
<input name="symbol" type="submit" value="5">
|
|
||||||
<input name="symbol" type="submit" value="6">
|
|
||||||
<input name="symbol" type="submit" value="-">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="1">
|
|
||||||
<input name="symbol" type="submit" value="2">
|
|
||||||
<input name="symbol" type="submit" value="3">
|
|
||||||
<input name="symbol" type="submit" value="+">
|
|
||||||
<br>
|
|
||||||
<input name="symbol" type="submit" value="+-">
|
|
||||||
<input name="symbol" type="submit" value="0">
|
|
||||||
<input name="symbol" type="submit" value=".">
|
|
||||||
<input name="symbol" type="submit" value="=">
|
|
||||||
</p>
|
|
||||||
</form>
|
|
||||||
<%
|
|
||||||
}
|
}
|
||||||
catch(NumberFormatException e) {
|
// 減法
|
||||||
throw new NumberFormatException("您輸入的不是整數");
|
void subtract() {
|
||||||
}
|
number[0] -= number[1];
|
||||||
|
}
|
||||||
|
// 乘法
|
||||||
|
void multiply() {
|
||||||
|
number[0] *= number[1];
|
||||||
|
}
|
||||||
|
// 除法
|
||||||
|
void divide() {
|
||||||
|
number[0] /= number[1];
|
||||||
|
}
|
||||||
|
// 取餘
|
||||||
|
void remainder() {
|
||||||
|
number[0] %= number[1];
|
||||||
|
}
|
||||||
|
//清除
|
||||||
|
void clear() {
|
||||||
|
number[0] = 0;
|
||||||
|
number[1] = 0;
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
|
||||||
|
<form action="calculator.jsp" method=post>
|
||||||
|
<p>
|
||||||
|
<input name="symbol" type="submit" value="%">
|
||||||
|
<input name="symbol" type="submit" value="root">
|
||||||
|
<input name="symbol" type="submit" value="square">
|
||||||
|
<input name="symbol" type="submit" value="reciprocal">
|
||||||
|
<br>
|
||||||
|
<input name="symbol" type="submit" value="CE">
|
||||||
|
<input name="symbol" type="submit" value="C">
|
||||||
|
<input name="symbol" type="submit" value="X">
|
||||||
|
<input name="symbol" type="submit" value="/">
|
||||||
|
<br>
|
||||||
|
<input name="symbol" type="submit" value="7">
|
||||||
|
<input name="symbol" type="submit" value="8">
|
||||||
|
<input name="symbol" type="submit" value="9">
|
||||||
|
<input name="symbol" type="submit" value="*">
|
||||||
|
<br>
|
||||||
|
<input name="symbol" type="submit" value="4">
|
||||||
|
<input name="symbol" type="submit" value="5">
|
||||||
|
<input name="symbol" type="submit" value="6">
|
||||||
|
<input name="symbol" type="submit" value="-">
|
||||||
|
<br>
|
||||||
|
<input name="symbol" type="submit" value="1">
|
||||||
|
<input name="symbol" type="submit" value="2">
|
||||||
|
<input name="symbol" type="submit" value="3">
|
||||||
|
<input name="symbol" type="submit" value="+">
|
||||||
|
<br>
|
||||||
|
<input name="symbol" type="submit" value="+-">
|
||||||
|
<input name="symbol" type="submit" value="0">
|
||||||
|
<input name="symbol" type="submit" value=".">
|
||||||
|
<input name="symbol" type="submit" value="=">
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
|
||||||
}
|
<%
|
||||||
|
// 輸入的字元
|
||||||
|
|
||||||
|
try {
|
||||||
|
String inputdata = request.getParameter("symbol");
|
||||||
|
if(inputdata == null) {
|
||||||
|
inputdata = "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inputdata.equals("CE")) {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
// 如果是數字就累積輸入
|
||||||
|
else if (inputdata.equals("0") ||
|
||||||
|
inputdata.equals("1") ||
|
||||||
|
inputdata.equals("2") ||
|
||||||
|
inputdata.equals("3") ||
|
||||||
|
inputdata.equals("4") ||
|
||||||
|
inputdata.equals("5") ||
|
||||||
|
inputdata.equals("6") ||
|
||||||
|
inputdata.equals("7") ||
|
||||||
|
inputdata.equals("8") ||
|
||||||
|
inputdata.equals("9")) {
|
||||||
|
// 輸入多位數字
|
||||||
|
number[i] *= 10;
|
||||||
|
number[i] += Float.parseFloat(inputdata);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 如果有選擇的運算子
|
||||||
|
if (oprator != 0) {
|
||||||
|
switch (oprator) {
|
||||||
|
case 1:
|
||||||
|
add();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
subtract();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
multiply();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
divide();
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
remainder();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inputdata.equals("=")) {
|
||||||
|
// 清除運算子
|
||||||
|
oprator = 0;
|
||||||
|
// 回到第一個運算元
|
||||||
|
i = 0;
|
||||||
|
number[1] = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 回到第二個運算元
|
||||||
|
i = 1;
|
||||||
|
number[1] = 0;
|
||||||
|
// 把運算
|
||||||
|
if (inputdata.equals("+")) {
|
||||||
|
oprator = 1;
|
||||||
|
}
|
||||||
|
else if (inputdata.equals("-")) {
|
||||||
|
oprator = 2;
|
||||||
|
}
|
||||||
|
else if (inputdata.equals("*")) {
|
||||||
|
oprator = 3;
|
||||||
|
}
|
||||||
|
else if (inputdata.equals("/")) {
|
||||||
|
oprator = 4;
|
||||||
|
}
|
||||||
|
else if (inputdata.equals("%")) {
|
||||||
|
oprator = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 印出現在的數字
|
||||||
|
out.println(number[i]);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
// 錯誤訊息
|
||||||
|
throw new NumberFormatException("您輸入的不是整數");
|
||||||
|
}
|
||||||
%>
|
%>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Reference in New Issue
Block a user