1.p39 实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
  </head>
  
  <body>
    <%Calendar c=Calendar.getInstance(); 
    int year=c.get(Calendar.YEAR); 
    int month=c.get(Calendar.MONTH); 
    int date=c.get(Calendar.DATE);     
    int hour=c.get(Calendar.HOUR); 
    int minute=c.get(Calendar.MINUTE); 
    int second=c.get(Calendar.SECOND); 
    String str=""; 
    if(hour>=0&&hour<=12){ 
    str="上午好"; 
    } 
    else if(hour>=13&&hour<=17){ 
    str="下午好"; 
    } 
    else if(hour>=18&&hour<=23){ 
    str="晚上好"; 
    } 
    %>
    <table BORDER="1"align="center">
    <tr align="center"><td>现在时间为<%=year %>-<%=month %>-<%=hour %>-<%=minute %>-<%=second %></td></tr>
    <tr align="center"><td><%=str %></td></tr>
    </table>
  </body>
</html>

 2. 使用声明方法,在页面调用该方法,判断2023是不是闰年

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%! boolean b(int x){
return x%4==0||x%100!=0&&x%400==0;
}
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>
  <body>
  判断2023是不是闰年:<%=b(2023) %><!-- 调用并输出结果 -->
  </body>
</html>

3.表达式+程序段 循环输出5条hr,长度分别为100px-500px

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  </head>
  <body>
    <%
    for(int x=1;x<=5;x++){    
     %>                              <%--循环5次输出直线 --%>
     <hr width="<%=x*100%>px">
     <br>
     <%} %>
     
  </body>
</html>

 

 posted on 2022-03-19 21:03  莉莉娅king  阅读(10)  评论(0编辑  收藏  举报