Spring

26. jsp별찍기 - 패스트캠퍼스 백엔드 부트캠프 3기

gkss2tpt 2025. 2. 9. 15:58
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>별찍기</title>
</head>
<body>
    <c:forEach var="i" begin="1" end="5">
        <c:forEach var="j" begin="1" end="5">
            <c:choose>
                <c:when test="${ i == j}">
                    *
                </c:when>
                <c:otherwise>
                    &nbsp;
                </c:otherwise>
            </c:choose>
        </c:forEach>
        <br>
    </c:forEach>
    ㅡㅡㅡㅡㅡ<br>
    <c:forEach var="i" begin="1" end="5">
        <c:forEach var="j" begin="1" end="5">
            <c:choose>
                <c:when test="${i+j==6}">
                    *
                </c:when>
                <c:otherwise>
                    &nbsp;
                </c:otherwise>
            </c:choose>
        </c:forEach>
        <br>
    </c:forEach>
    ㅡㅡㅡㅡㅡ<br>
    <c:forEach var="i" begin="1" end="5">
        <c:forEach var="j" begin="1" end="5">
            <c:choose>
                <c:when test="${i==j || i+j==6}">
                    *
                </c:when>
                <c:otherwise>
                    &nbsp;
                </c:otherwise>
            </c:choose>
        </c:forEach>
        <br>
    </c:forEach>
    ㅡㅡㅡㅡㅡ<br>
    <%
        int count1 = 5; int count2 = 5;
        request.setAttribute("count1", count1);
        request.setAttribute("count2", count2);
    %>
    <c:forEach var="i" begin="1" end="5">
        <c:forEach var="j" begin="1" end="10">
            <c:choose>
                <c:when test="${j>=count1 && j <= count2}">
                    *
                </c:when>
                <c:otherwise>
                    &nbsp;
                </c:otherwise>
            </c:choose>
        </c:forEach>
        <%
            count1--;
            count2++;
            request.setAttribute("count1", count1);
            request.setAttribute("count2", count2);
        %>
        <br>
    </c:forEach>
</body>
</html>