[JSP, HTML5]구구단
[JSP, HTML5]구구단
FOR문 두개로 TABLE의 가로( j ) 세로( i )를 만들어
내부 FOR문에서 IF문으로 총 4부분을 나누어서 설정 하였습니다.
<웹페이지>
<코드>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>구구단</title> </head> <body> <center> <form> <h3 font-size=30px;>구구단</h3> <br> <TABLE border="1"> <% for (int i = 0; i < 10; i++) {/* 구구단표의 세로 */ %> <TR align="center"> <% for (int j = 1; j < 10; j++) {/* 구구단의 가로 */ %> <% if (i == 0 && j == 1) { /* 상단왼쪽칸 */ %> <TD bgcolor="red"></TD> <% } else if (j == 1) { %> <TD width="69" bgcolor="red"><%=(i)%></TD> <% } else if (i == 0) { %> <TD width="69" bgcolor="red"><%=(j)%></TD> <% } else { %> <TD><%=(j + "x" + i + "=" + i * j)%></TD> <% } %> <% } %> </TR> <% } %> </table> </form> </center> </body> </html> | cs |