第二次作业
1.p39 实验2 显示当前时间,并输出上午(0-12)好,下午好(13-17),晚上好(18-23)
<body> <% Date date = new Date();/* 获取方法 */ int hour = date.getHours(); int minute = date.getMinutes(); int second = date.getSeconds(); out.print("当前时间:" + hour + ":" + minute + ":" + second + "<br>");//获取时间 if (hour >= 0 && hour <= 12) { out.print("早上好"); } else if (hour >= 13 && hour <= 17) { out.print("中午好"); } else if (hour >= 18 && hour <= 23) { out.print("晚上好"); } %> </body>
2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <!-- 判断润年 --> <body> <%!String y(int year) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { return "该年是闰年"; } else { return "该年不是闰年"; } }%> <% String year = y(2023); out.print(year); %> </body> </html>
3.表达式+程序段 循环输出5条hr,长度分别为100px-500px
<hr width="<%=i%>" <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <%for(int i=1;i<=5;i++){ %> <hr width="<%=i*100%>"> <% } %> </body> </html>