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>
<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>
Thanks sir gives me solution
ReplyDeleteThis 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.
ReplyDeleteThis 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