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

  1. Thanks sir gives me solution

    ReplyDelete
  2. This post highlights the importance of system design for building efficient and scalable software applications. Learning how systems are designed and optimized is a great skill for developers. Anyone interested can explore Best System Design with Java Online Training in Hyderabad to gain hands-on knowledge of modern software architecture.

    ReplyDelete
  3. This is a very informative article for Java learners. Strengthen your coding and Core Java fundamentals with Top Core JAVA Online Training in Hyderabad and gain practical industry experience.

    ReplyDelete

Post a Comment

Popular posts from this blog

Write a socket program in java for simple stand alone chatting application.

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)