第二次作业3.9
输出当前时间,并根据时间输出早上好,下午好,晚上好 <body> <% Date sj=new Date(); int hour=sj.getHours(); int min=sj.getMinutes(); int se=sj.getSeconds(); out.print("当前时间为:"+hour+":"+min+":"+se+"<br>"); if(hour>=0&&hour<=12){ %> <p style="font-size:20;color:blue">早上好</p>//注释 <% }else if(hour>=13&&hour<=17){ %> <p style="font-family:宋体;font-size:20;color:blue">下午好</p> <% } else { out.print("晚上好"); } %> </body>
2. 使用声明方法,在页面调用该方法,判断2023是不是闰年 闰年:能被4整除但不能被100整除或者能被400整除 <body> <!-- 定义方法judy --> <%!int judy(int year){ if (year%4==0&year%400==0){ return 0; } else{ return 1; }} %> <% int year=2023; int i=judy(year); if (i==0){ out.println("是闰年"); } else{ out.println("不是闰年"); } %> </body>
<head> </head> <body> <% for(int i=100;i<=500;i+=100){ %> <hr style="color:blue" width="<%=i%>"><% } %> <%--颜色为蓝色 --%> </body></html>
<body>
<%
Date sj=new Date();
int hour=sj.getHours();
int min=sj.getMinutes();
int se=sj.getSeconds();
out.print("当前时间为:"+hour+":"+min+":"+se+"<br>");
if(hour>=0&&hour<=12){
%>
<p style="font-size:20;color:blue">早上好</p>//注释
<%
}else if(hour>=13&&hour<=17){
%>
<p style="font-family:宋体;font-size:20;color:blue">下午好</p>
<%
}
else {
out.print("晚上好");
}
%>
</body>