计算阶乘和 请教大侠那个地方出错了 ..
<%@ 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>Insert title here</title>
</head>
<body>
<form action="提交到本页" method="post">
<input type="text" name="num">
<input type="submit" value="计算">
</form>
<%!public int getFactorial(int n){
if (n == 1||n == 0)
return 1;
else
return n*getFactorial(n - 1);
}%>
<%!public int getResult(){
int sum=0,n;
for(int i=1;i<=n;i++)
{
sum+=getFactorial(i);
}
return sum;
}%>
<%
int num = 0;
String str = request.getParameter("num");
if (str!=null)
num = Integer.parseInt(str);
%>
<%=getResult() %>
</body>
</html>