zoukankan      html  css  js  c++  java
  • 20

    package room1;

    import java.time.*;
    import java.time.temporal.*;

    class Clock {
    public static void main(String[] arguments) {
    // get current time and date
    LocalDateTime now = LocalDateTime.now();
    int hour = now.get(ChronoField.HOUR_OF_DAY);
    int minute = now.get(ChronoField.MINUTE_OF_HOUR);
    int month = now.get(ChronoField.MONTH_OF_YEAR);
    int day = now.get(ChronoField.DAY_OF_MONTH);
    int year = now.get(ChronoField.YEAR);

    // display greeting
    if (hour < 12) {
    System.out.println("Good morning. ");
    } else if (hour < 17) {
    System.out.println("Good afternoon. ");
    } else {
    System.out.println("Good evening. ");
    }

    // begin time message by showing the minutes
    System.out.print("It's");
    if (minute != 0) {
    System.out.print(" " + minute + " ");
    System.out.print( (minute != 1) ? "minutes" :
    "minute");
    System.out.print(" past");
    }

    // display the hour
    System.out.print(" ");
    System.out.print( (hour > 12) ? (hour - 12) : hour );
    System.out.print(" o'clock on ");

    // display the name of the month
    switch (month) {
    case 1:
    System.out.print("January");
    break;
    case 2:
    System.out.print("February");
    break;
    case 3:
    System.out.print("March");
    break;
    case 4:
    System.out.print("April");
    break;
    case 5:
    System.out.print("May");
    break;
    case 6:
    System.out.print("June");
    break;
    case 7:
    System.out.print("July");
    break;
    case 8:
    System.out.print("August");
    break;
    case 9:
    System.out.print("September");
    break;
    case 10:
    System.out.print("October");
    break;
    case 11:
    System.out.print("November");
    break;
    case 12:
    System.out.print("December");
    }

    // display the date and year
    System.out.println(" " + day + ", " + year + ".");
    }
    }

  • 相关阅读:
    [转]xshell实现端口转发
    Windows下gvim配置
    Linux环境下段错误的产生原因及调试方法小结
    elasticsearch的服务器响应异常及应对策略
    scp不可用:WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED
    windows下python安装pyquery
    python实现简单爬虫功能
    关于Elasticsearch单个索引文档最大数量问题
    pthread_mutex_lock
    一道模拟题:改进的Joseph环
  • 原文地址:https://www.cnblogs.com/acm-icpcer/p/6536322.html
Copyright © 2011-2022 走看看