JSP编程统计:1到100中分别计算奇数和偶数的和(用For和while语句)
JSP编程统计:1到100中分别计算奇数和偶数的和(用For和while语句)求代码,JSP编程!...
JSP编程统计:1到100中分别计算奇数和偶数的和(用For和while语句)
求代码,JSP编程! 展开
求代码,JSP编程! 展开
1个回答
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<%
int A = 0, B = 0, i = 0;
while (i++ < 101) {
if (i % 2 == 0) {
A += i;
} else {
B += i;
}
out.println("(while)偶数的和为:" + A + ".");
out.println("(while)奇数的和为:" + B + ".");
}
%>
<%
int a = 0, b = 0, j = 0;
for(;i<101;i++){
if (j % 2 == 0) {
a += j;
} else {
b += j;
}
out.println("(for)偶数的和为:" + a + ".");
out.println("(for)奇数的和为:" + b + ".");
}
%>
</body>
</html>
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
</head>
<body>
<%
int A = 0, B = 0, i = 0;
while (i++ < 101) {
if (i % 2 == 0) {
A += i;
} else {
B += i;
}
out.println("(while)偶数的和为:" + A + ".");
out.println("(while)奇数的和为:" + B + ".");
}
%>
<%
int a = 0, b = 0, j = 0;
for(;i<101;i++){
if (j % 2 == 0) {
a += j;
} else {
b += j;
}
out.println("(for)偶数的和为:" + a + ".");
out.println("(for)奇数的和为:" + b + ".");
}
%>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询