简单的Java计数器
写的第一个java 项目,有点简陋
package Zhang691;
import java.math.BigDecimal;
public class day0318 {
private String i1="1"; //
private String j="+";
private String i2="1";
private String k="2";
public String getK() {
return k;
}
public void setK(String k) {
this.k = k;
}
public String getI1() {
return i1;
}
public void setI1(String i1) {
this.i1 = i1;
}
public String getJ() {
return j;
}
public void setJ(String j) {
this.j = j;
}
public String getI2() {
return i2;
}
public void setI2(String i2) {
this.i2 = i2;
}
public String check(){
Double I1=new Double(i1);
Double I2=new Double(i2);
switch (j) {
case "+":
k=String.valueOf(I1+I2);
break;
case "-":
k=String.valueOf(I1-I2);
break;
case "*":
k=String.valueOf(I1*I2);
break;
case "/":
if (I2==0){
k="除数不能为零";break;
}else {
k=String.valueOf(I1/I2);
break;
}
default:k="符号错误";
break;
}
return k;
}
}
index部分:
<%@ 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>计数器</title>
</head>
<body>
<jsp:useBean id="day0318" class="Zhang691.day0318"></jsp:useBean>
<jsp:setProperty property="*" name="day0318"/>
<form>
第一个数:<input name="i1" type="text" value="123"></input>
<br>
运算符号:<select name="j" >
<option value="+">相加</option>
<option value="-">相减</option>
<option value="*">相乘</option>
<option value="/">相除</option>
</select>
<br>
第二个数:<input name="i2" type="text" value="456"></input>
<br>
<input type="submit" value="计算">
<input type="reset" value="重填">
<br>
<hr>
</form>
<%
day0318.check();
%>
运行结果:
<jsp:getProperty property="i1" name="day0318"/>
<jsp:getProperty property="j" name="day0318"/>
<jsp:getProperty property="i2" name="day0318"/> =
<jsp:getProperty property="k" name="day0318"/>
<hr>
</body>
</html>