Advertisement
Guest User

adsadsa

a guest
Jan 29th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.18 KB | None | 0 0
  1. <%--
  2.     Document   : MultiTab
  3.     Created on : Jan 30, 2015, 11:34:10 AM
  4.     Author     : INT303
  5. --%>
  6.  
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8. <!DOCTYPE html>
  9. <html>
  10.     <head>
  11.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  12.         <title>Multiplication Table</title>
  13.     </head>
  14.     <body>
  15.         <h1>Multiplication Table ::</h1><hr>
  16.         <%
  17.             String para = request.getParameter("num");
  18.             if (para == null) {
  19.         %>
  20.         <h3><font color=red>Invalid request ... Please provide request parameter 'num' !!!</font></h3>
  21.             <%
  22.             } else if (para.length() == 0) {%>
  23.         <h3><font color=red>Invalid request ... num must be Positive Integer ONLY !!!</font></h3>
  24.             <%
  25.             } else {
  26.                 try {
  27.                     int num = Integer.parseInt(para);
  28.                     if (num > 0) {
  29.                         String message = getTable(num);
  30.                         out.println(message);
  31.                     } else { %>
  32.         <h3><font color=red>Invalid request ... num must be Positive Integer ONLY !!!</font></h3>
  33.             <%}
  34.             } catch (Exception e) {%>
  35.         <h3><font color=red>Invalid request ... num must be Positive Integer ONLY !!!</font></h3>
  36.             <%
  37.                     }
  38.                 }
  39.             %>
  40.             <%!
  41.                 private String getTable(int x) {
  42.                     StringBuilder sb = new StringBuilder();
  43.                     sb.append("<table cellspacing='0' border='0'><tr><td bgcolor='#6495ED' colspan='5'>Multiplication Table of " + x + "</td></tr>");
  44.                     String bgColor = "white";
  45.                     for (int i = 1; i <= 12; i++) {
  46.                         sb.append("<tr bgcolor=" + bgColor + "><td>" + x + "</td><td>x</td><td>" + i + "</td>");
  47.                         sb.append("<td> = </td><td>" + x * i + "</td></tr>\n");
  48.                         bgColor = bgColor.equalsIgnoreCase("white") ? "lightgray" : "white";
  49.                     }
  50.                     sb.append("</table>");
  51.                     return sb.toString();
  52.                 }
  53.             %>
  54.     </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement