计算阶乘和 请教大侠那个地方出错了 ..

Java_ILU 2012-10-10 07:21:47
<%@ 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>
...全文
22 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧