웹개발 교육/jsp

[47일] jsp (5) - 배열

2022. 10. 4. 18:05
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>03_배열.jsp</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
	<h3>배열</h3>
<%
	String[] uname= {"라일락","진달래","개나리","무궁화","홍길동"};
	int[] kor= {100, 50, 95, 80, 60};
	int[] eng= {100, 55, 95, 85, 40};
	int[] mat= {100, 60, 35, 90, 30};
	int size=uname.length; //5

	//평균 구하기
	int[] aver = {0, 0, 0, 0, 0};
	for(int i=0; i<size; i++) {
		aver[i]=(kor[i]+eng[i]+mat[i])/3;
	}//for end
		
	//등수 구하기(평균을 기준으로)
	int[] rank = {1, 1, 1, 1, 1};
	for(int a=0; a<size; a++) {
		for(int b=0; b<size; b++){
			if(aver[a]<aver[b]){
				rank[a]=rank[a]+1;
			}//if end
		}//for end
	}//for end
%>	
	
</body>
</html>

예전 java 시간에 했던 성적 구하는 코드이다. 여기에 부트스트랩을 이용해 표로 출력을 해보자

 

<!-- 출력 -->
<div class="container">
    <table class="table">
    <thead>
        <tr class="success">
            <th>이름</th>
            <th>국어</th>
            <th>영어</th>
            <th>수학</th>
            <th>평균</th>
            <th>등수</th>
            <th>결과</th>				
        </tr>
    </thead>
    <tbody>
<%
    for(int i=0; i<size; i++){
%>
        <tr>
            <td><%=uname[i]%></td>
            <td><%=kor[i]%></td>
            <td><%=eng[i]%></td>
            <td><%=mat[i]%></td>
            <td><%=aver[i]%></td>
            <td><%=rank[i]%></td>
            <td>
<%
                if(aver[i]>=70){
                    if(kor[i]<40 || eng[i]<40 || mat[i]<40){
                        out.print("재시험");
                    } else {
                        out.print("합 격");
                    }//if end
                } else {
                    out.print("불합격");
                }//if end

                for(int star=0; star<aver[i]/10; star++){
                    out.print("*");
                }//for end

                //평균 95이상이면 장학생 (진하게, 빨강색)
                if(aver[i]>=95){
                    out.print("<span style='color:red; font-weight:bold;'>");
                    out.print("장학생");
                    out.print("</span>");
                }//if end
%>
            </td>				
        </tr>
<%		
    }//for end
%>

    </tbody>		
    </table>
</div>

'웹개발 교육 > jsp' 카테고리의 다른 글

[48일] jsp (7) - 내부 객체  (0) 2022.10.05
[48일] jsp (6) - 함수  (0) 2022.10.05
[47일] jsp (4) - 표현식  (0) 2022.10.04
[47일] jsp (3) - 기본 문법  (0) 2022.10.04
[47일] jsp (2) - 이클립스 Tomcat 연동  (0) 2022.10.04
'웹개발 교육/jsp' 카테고리의 다른 글
  • [48일] jsp (7) - 내부 객체
  • [48일] jsp (6) - 함수
  • [47일] jsp (4) - 표현식
  • [47일] jsp (3) - 기본 문법
ewok
ewok
ewok
기록장
ewok
전체
오늘
어제
  • 분류 전체보기
    • 웹개발 교육
      • HTML
      • CSS
      • JavaScript
      • Database
      • Java
      • jQuery
      • Ajax
      • Bootstrap
      • jsp
      • Spring
      • MyBatis
      • 프로젝트
    • JAVA
    • SpringBoot
      • 기초
      • AWS
      • 개인프로젝트
    • Spring Security
    • JPA
    • 테스트코드
    • Error
    • CS
      • 컴퓨터 구조
      • 이산수학
    • 알고리즘
      • 정리
      • Java
    • SQL
    • 자격증
      • SQLD
      • 정보처리기사
    • Git

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • GIT
  • 브랜치
  • sqld 자격증
  • org.hibernate.tool.schema.spi.CommandAcceptanceException
  • base
  • sqld 합격
  • 버전 관리
  • git bash
  • org.springframework.beans.factory.UnsatisfiedDependencyException
  • branch
  • 노랭이
  • 생성자
  • this
  • SQLD
  • merge commit

최근 댓글

최근 글

hELLO · Designed By 정상우.
ewok
[47일] jsp (5) - 배열
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.