Wednesday, April 15, 2009

Exercises 2 lab 1

Write a program using JSP to calculate the sum of numbers from 1 to 25.

Solution:
<html>
<head>
<title>JSP Example</title>
</head>
<body>
<h1>Displaying sum</h1>
<%
int sum=0;
for(int num=1;num<=25;num++)
{
sum=sum+num;
}
out.println("Sum of numbers from 1 to 25 is : " + sum);
%>
</body>
</html>


The output of the program is as shown in Figure 2.2.

Figure 2.2: Output of Sum.jsp

0 nhận xét: