JSP
chapter02 : script_element
GAWON
2023. 5. 22. 09:18
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>0~9 사이에 모든 정수 출력하기</h2>
<%for(int i=0; i<10; i++){%>
i <%--문자열 출력 --%>
<%}%>
<h2>0~9 사이에 모든 정수 출력하기</h2>
<%for(int i=0; i<10; i++){%>
<%=i %>
<%}%>
<h2>1~100 사이의 모든 정수의 합계를 구해서 출력하기</h2>
<%
int total = 0;
for(int i=1; i<101; i++){
total += i;
}
%>
1~100 사이의 합 = <%=total %>
<h2>1~100사이의 모든 짝수를 합계를 리턴하는 even() 메소드</h2>
<%!
public int even(){
int evenSum = 0;
for(int i=1; i <101; i++){
if(i % 2 == 0){
evenSum += i;
}
}
return evenSum;
}
%>
1~100 사이의 모든 짝수의 합=<%=even()%>
<h2>1~100사이의 모든 홀수의 합계를 리턴하는 odd() 메소드</h2>
<%!
public int odd(){
int oddSum = 0;
for(int i=1; i <101; i++){
if(i % 2 == 0){
oddSum += i;
}
}
return oddSum;
}
%>
1~100 사이의 모든 홀수의 합 = <%=odd()%>
</body>
</html>