Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%--
- Document : MultiTab
- Created on : Jan 30, 2015, 11:34:10 AM
- Author : INT303
- --%>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Multiplication Table</title>
- </head>
- <body>
- <h1>Multiplication Table ::</h1><hr>
- <%
- String para = request.getParameter("num");
- if (para == null) {
- %>
- <h3><font color=red>Invalid request ... Please provide request parameter 'num' !!!</font></h3>
- <%
- } else if (para.length() == 0) {%>
- <h3><font color=red>Invalid request ... num must be Positive Integer ONLY !!!</font></h3>
- <%
- } else {
- try {
- int num = Integer.parseInt(para);
- if (num > 0) {
- String message = getTable(num);
- out.println(message);
- } else { %>
- <h3><font color=red>Invalid request ... num must be Positive Integer ONLY !!!</font></h3>
- <%}
- } catch (Exception e) {%>
- <h3><font color=red>Invalid request ... num must be Positive Integer ONLY !!!</font></h3>
- <%
- }
- }
- %>
- <%!
- private String getTable(int x) {
- StringBuilder sb = new StringBuilder();
- sb.append("<table cellspacing='0' border='0'><tr><td bgcolor='#6495ED' colspan='5'>Multiplication Table of " + x + "</td></tr>");
- String bgColor = "white";
- for (int i = 1; i <= 12; i++) {
- sb.append("<tr bgcolor=" + bgColor + "><td>" + x + "</td><td>x</td><td>" + i + "</td>");
- sb.append("<td> = </td><td>" + x * i + "</td></tr>\n");
- bgColor = bgColor.equalsIgnoreCase("white") ? "lightgray" : "white";
- }
- sb.append("</table>");
- return sb.toString();
- }
- %>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement