1. 程式人生 > >任意兩數求累加值

任意兩數求累加值

 提交.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>提交任意兩數的頁面</title>
</head>
<body>
	<form action="任意兩數累加值_輸出.jsp">
		開始資料:<input name="shuju1"><br><br>
		結束資料:<input name="shuju2"><br><br>
		<input type="submit" value="提交">
	</form>
</body>
</html>

輸出.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>計算任意兩整數之間的累加和值的JSP程式</title>
</head>
<body>
	<%! int sum=0;
		int x=0; int y=0;
	%>
	<% 	sum=0;
		String xx=request.getParameter("shuju1");
		String yy=request.getParameter("shuju2");
		x=Integer.parseInt(xx);
		y=Integer.parseInt(yy);
		while(x<=y){
			sum+=x;
			++x;
		}
	%>
	<p><%=xx %>加到<%=yy %>的和值是:<%=sum %></p>
	<p>現在的時間是:<%=new Date() %></p>
</body>
</html>