Write a JSP program to calculate sum of first and last digit of a given number. Display sum in Red Color with font size 18.

Number.html

<html>
<body>
<form method=get action="Number.jsp">
Enter Any Number : <Input type=text name=num><br><br>
<input type=submit value=Calculate>
</form>
</body>
</html>

Number.jsp

<html>
<body>
<%! int n,rem,r; %>
<% n=Integer.parseInt(request.getParameter("num"));
      if(n<10)
     {
       out.println("Sum of first and last digit is   ");
%><font size=18 color=red><%= n %></font>
<%
     }
    else
    {
      rem=n%10;
      do{
                 r=n%10;
                 n=n/10;
            }while(n>0);
         n=rem+r;
        out.println("Sum of first and last digit is    ");
%><font size=18 color=red><%= n %></font>
<%
     }
%>
</body>
</html>

Comments

Post a Comment

Popular posts from this blog

Write a java program to create Teacher table(TNo.TName, Sal, Desg) and insert a record in it.

Create a JSP page to accept a number from an user and display it in words: Example: 123 – One Two Three. The output should be in red color.

Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it into database and display it in tabular form. (Use PreparedStatement interface)