日期:2014-05-16  浏览次数:20573 次

Jsp查找闰年
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  
    <title>查找闰年</title>    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
  </head>  
  <body>
    <%!
    	boolean findYear(int year){
    		if(((year%4==0)&&(year%100!=0)) || year%400==0){
    			return true;
    		}else{
    			return false;
    		}
    	}
     %>
     
     <%
     	int count = 0;
     	StringBuffer sb = new StringBuffer();
     	for(int i=2000; i<=2010; i++){
     		if(findYear(i)){
     		count++;
     		sb.append(i).append("&nbsp;&nbsp;");
     		}
     	}
      %>
      从2000年到2010年期间,共有<%=count %>个闰年,分别是<%=sb.toString() %>
  </body>
</html>

?

效果图:

?