第二周上机作业

显示当前时间,并输出上午(0~12)好,下午好(12~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></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 x = "";   
        if (hour >= 0 && hour <= 12) { 
            x = "上午好!";
        } else if (hour >= 13 && hour <= 17) {
            x = "下午好!";
        } else if (hour >= 18 && hour <= 23) {
            x = "晚上好!";
        }
    %>
    <p>
        当前时间为:<%=year%>/<%=month%>/<%=date%>
        <%=hour%>:<%=minute%>:<%=second%><br>
    </p>
    <p><%=x%></p> <br>
  </body>
</html>

 

 

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

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
  </head>
  <!--HTML-->
  <body>
      <h1>判断闰年</h1>
    <%!
    String panduan(int a){
        if((a%4==0&&a%100!=0)||a%400==0){
            return "闰年";
        }else{
            return "平年";
        }
    }
     %>
     <%
     int a=2023;
     out.print("2023为"+panduan(a));
      %>
  </body>
</html>

 

 

.表达式+程序段 循环输出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>
    
  </head>
  
  <body>
      
    <%
    for(int i=100;i<=500;i=i+100){    
     %>
     <hr width="<%=i%>" /><br>
     <%} %>
  </body>
</html>

 

posted @ 2022-03-12 11:33  叼个奶嘴闯天下  阅读(9)  评论(0编辑  收藏  举报