第二次作业

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> 
    <title>My JSP 'index.jsp' starting page</title>
  </head>
  <body>
  <%
  Calendar c=Calendar.getInstance();
  int year=c.get(Calendar.YEAR);//获取年
  int month=c.get(Calendar.MONTH)+1;//获取月
  int date=c.get(Calendar.DATE);//获取日
  int hour=c.get(Calendar.HOUR_OF_DAY);//获取时
  int minute=c.get(Calendar.MINUTE);//获取分
  int second=c.get(Calendar.SECOND);//获取秒
  String a="";//通过字符串输出内容
  if(hour>=0&&hour<=12){//使用条件语句
  a="上午好!";
  }else if(hour>=13&&hour<=17){
  a="中午好!";
  }else if(hour>=18&&hour<=23){
  a="晚上好!";
  }
   %>
   <p>现在的时间为:<br></p>
   <p><%=year%>/<%=month%>/<%=date%><br></p>
   <p><%=hour%>:<%=minute%>:<%=second%><br></p>
   <p><%=a%></p>
  </body>
</html>

 

2. 使用声明方法,在页面调用该方法,判断2023是不是闰年
闰年:能被4整除但不能被100整除或者能被400整

<%@ 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>
<title>My JSP 'index.jsp' starting page</title>
<!-- HTML注释 -->
<%!boolean a(int year) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            return true;
        } else {
            return false;
        }
    }%>
</head>
<body>
    <%
        boolean b = a(2023);
        out.print(b);
    %>
</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注释 -->
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</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">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
</head>
<%--jsp注释 --%>
<body>
    <%
        for (int i = 1; i <= 5; i++) {
    %>
    <hr width="<%=i * 100%>px">
    <%
        }
    %>
</body>
</html>
复制代码

 

posted @ 2022-03-11 22:30  计算机1905王子健  阅读(15)  评论(0编辑  收藏  举报