<!--
2단 ~ 9단까지 출력(반복문) 테이블에 넣어서
출력결과
==구구단==
2단 3단 4단 5단
2*2=2 3*2=6 4*2=8 5*2=10
2*3=6 3*3=9 4*3=12 5*3=15
2*4=8 3*4=12 4*4=16 5*4=20
2*5=10 3*5=15 4*5=20 5*5=25
2*6=12 3*6=18 4*6=24 5*6=30
2*7=14 3*7=21 4*7=28 5*7=35
2*8=16 3*8=24 4*8=32 5*8=40
2*9=18 3*9=27 4*9=36 5*9=45
6단 7단 8단 9단
6*2=12 7*2=14 8*2=16 9*2=18
: : : :
-->
<script language="JavaScript">
// FOR문 사용 ▽▽▽▽▽▽▽▽▽▽▽▽▽
document.write("<table border=10 width=360 height=600 cellspacing=0 cellpadding=0>");
document.write("<caption align=center><h2>== 구구단 ==</h2></caption>");
document.write("<tr>");
for (n=2; n<6; n++) // 첫째줄 2단~5단 표시
{
document.write("<td align=center>"+n+" 단</td>"); // n=2,3,4,5 / 4번 반복해서 4열
}
document.write("</tr>"); // 행 닫고
for (a=1; a<10; a++) // 단에 곱해질 숫자 : 행 1,2,3,4,5,6,7,8,9
{
document.write("<tr>"); // 행 열고
for (b=2; b<6; b++) // 단에 해당되는 숫자 : 열 2,3,4,5
{
document.write("<td align=center>"+b+" * "+a+" = "+b*a+"</td>");
}
}
document.write("</tr><tr height=20><td></td></tr><tr>"); // 분리선 역할
for (c=6; c<10; c++) // 두번째 시작의 6~9단 표시
{
document.write("<td align=center>"+c+" 단</td>") // c=6,7,8,9 / 4번 반복해서 4열
}
document.write("</tr>"); // 행 닫고
for (a=1; a<10; a++) // 단에 곱해질 숫자 다시 초기화 : 행 1,2,3,4,5,6,7,8,9
{
document.write("<tr>"); // 행 열고
for (b=6; b<10; b++) // 단에 해당되는 숫자 초기화 : 열 6,7,8,9
{
document.write("<td align=center>"+b+" * "+a+" = "+b*a+"</td>");
}
document.write("</tr>"); // 행 닫고
}
document.write("</table>"); // 테이블 닫고
document.write("<br><br><br>");
// WHILE문 사용 ▽▽▽▽▽▽▽▽▽▽▽▽▽
document.write("<table border=10 width=360 height=600 cellspacing=0 cellpadding=0>");
document.write("<caption align=center><h2>== 구구단 ==</h2></caption>");
document.write("<tr>");
n=2;
while (n<6)
{
document.write("<td align=center>"+n+" 단</td>");
n++;
}
document.write("</tr>");
a=1;
while (a<9)
{
document.write("<tr>");
a++;
b=2;
while (b<6)
{
document.write("<td align=center>"+b+" * "+a+" = "+b*a+"</td>");
b++;
}
}
document.write("</tr><tr height=20><td></td></tr><tr>");
c=6;
while (c<10)
{
document.write("<td align=center>"+c+" 단</td>")
c++;
}
document.write("</tr>");
a=1;
while (a<9)
{
document.write("<tr>");
a++;
b=6;
while (b<10)
{
document.write("<td align=center>"+b+" * "+a+" = "+b*a+"</td>");
b++;
}
document.write("</tr>");
}
document.write("</table>");
</script>
'Html/Jsp/Javascript' 카테고리의 다른 글
Html,Jsp,Css_08 (0) | 2011.10.19 |
---|---|
Html,Jsp,Css_07 (0) | 2011.10.18 |
Html,Jsp,Css_06 (0) | 2011.10.17 |
[Test] 회원가입 폼 만들기 (1) | 2011.10.16 |
Html,Jsp,Css_05 (0) | 2011.10.14 |