카테고리 없음

[JSP] 구구단 출력

너래쟁이 2018. 4. 12. 02:53



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
54
55
56
<%@ 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>
<style type="text/css">
td
{
    text-align:center;
}
</style>
</head>
<body>
<center>
<table border=1   align="center">
<%
    int i = 0;
    int j = 0;
    
    
    out.println("<td bgcolor='#F69696' width=70>");
    out.println(" ");
    out.println("</td>");
    for(i=1;i<=8 ;i++)
    {
        out.println("<td bgcolor='#F69696' width=70>");
        out.println(i+"단");
        out.println("</td>");
    }
    out.println("<tr>");
    for(i=1;i<=9 ;i++)
    {
        out.println("<td bgcolor='#F69696' width=70>");
        out.println(i);
        out.println("</td>");
        
        for(j=2;j<=9;j++)
        {
            
            out.println("<td>");
            out.println(j+"X"+i+"="+(i*j));
            if(j==9)
            {
                out.println("<tr>");
            }
            out.println("</td>");
        }
    }
%>
 
</table>
</center>
</body>
</html>
cs


기범style

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
<%@ 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><H2>구    구    단</H2>
<table border=1 align="center">
<%
    for(int i=0; i<=9; i++) {
    %>
    <%= "<tr>" %>
    <% for(int j=0; j<=9; j++) {
        if(i==0 && j==0) { %>
        <%= "<td width=70 bgcolor=red align=center></td>" %>
        <% } else if(i==0 && j!=0) { %>
        <%= "<td width=70 bgcolor=red align=center>" + j + "</td>" %>
        <% } else if(i!=0 && j==0) { %>
        <%= "<td width=70 bgcolor=red align=center>" + i + "</td>" %>
        <% } else { %>
        <%= "<td align=center>" + j + "x" + i + "=" + j*+ "</td>" %>
        <% } 
        }
    %>
    <%= "</tr>" %>
<% } %>
</table>
</center>
</body>
</html>
cs



정식style

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
<%@ 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>Insert title here</title>
</head>
<body>
   <center>
      <h2>구구단</h2>
      <table border="1">
      <tr align="center">
         <td bgcolor="#FFBBBD" width=40 ></td>
         <% for(int i=2;i<=9;i++) {%>
          <td  bgcolor="#FFBBBD"<%=i%></td>   <%}%>
      </tr>
 
         <% for(int i=1;i<=9;i++) {%>
      <tr align="center">
         <td bgcolor="#FFBBBD"><%=i%></td>
         <% for(int j=2;j<=9;j++
            {%>
          <td<%=j%> x <%=i%> = <%=j*i%> </td>
         <%}%>
        <%}%>
      </tr>
 
   </table>
   </center>
</body>
</html>
cs