博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2018/12/05 PAT刷题 L1-018 大笨钟 Java
阅读量:7286 次
发布时间:2019-06-30

本文共 1989 字,大约阅读时间需要 6 分钟。

花了很大的力气把题目从Scanner的输入方式改成BufferedReader和InputStreamReader的方式, 想法其实是很简单的, 就是执行的过程中, 不仔细, 导致有1个测试点一直过不去, 原来是输出语句有问题, 晕死了, 简单的题目就是考研耐性:

1 import java.io.BufferedReader; 2 import java.io.InputStreamReader; 3  4 public class Main { 5  6     public static void main(String[] args) throws Exception { 7         BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8         String string = br.readLine(); 9         String[] str = string.split(":");10         int hh = Integer.parseInt(str[0]);11         int mm = Integer.parseInt(str[1]);12         if (hh >= 0 && hh <= 11) {13             // 在[1,12)这个区间, 输出语句14             System.out.print("Only " + string + "." + "  Too early to Dang.");15         }16 17         if (hh == 12) {18             if (mm == 0) {19                 // 如果是上午12点整点, 输出语句.20                 System.out.print("Only " + string + "." + "  Too early to Dang.");  21             } else {22                 // 如果是12点非整点时间, 当作13点整点的情况输出语句23                 System.out.print("Dang");24             }25         }26         27         if (hh >= 13 && hh <= 23) {28             // 在下午1点到下午11点之间的情况.29             if (mm == 0) {30                 String[] st = new String[hh - 12];31                 for (int i = 0; i < hh - 12; i++) {32                     st[i] = "Dang";  // 输出hh-12个 "Dang"33                 }34                 for (int i = 0; i < hh - 12; i++) {35                     System.out.print(st[i]);  // 输出hh-12个 "Dang"36                 }37             } else {38                 // 在下午1点到下午11点的非整点的情况.39                 String[] st = new String[hh + 1 - 12];40                 for (int i = 0; i < hh + 1 - 12; i++) {41                     st[i] = "Dang";  // 输出hh-12+1个 "Dang"42                 }43                 for (int i = 0; i < hh + 1 - 12; i++) {44                     System.out.print(st[i]);  // 输出hh-12+1个 "Dang"45                 }46             }47         }48 49     }50 51 }

 

转载于:https://www.cnblogs.com/huangZ-H/p/10069760.html

你可能感兴趣的文章
django实例教程
查看>>
swift 中String常用操作
查看>>
oracle lock基础知识(一)
查看>>
eclipse alt+/ 无法使用或者显示不了方法
查看>>
[微擎]更改微擎后台顶部导航配色
查看>>
web报表functionChart教程
查看>>
ls命令实现分析
查看>>
使用 django-blog-zinnia 搭建个人博客
查看>>
设置一个临时变量交换两个变量的值
查看>>
java:关于SerialVersionUid
查看>>
nagios与cacti的整合
查看>>
使用RHEL6.3+PXE+DHCP+Apache+NFS+KickStart 无人值守安装RHEL6.3
查看>>
JXL GC 问题探讨
查看>>
并发编程四之互斥
查看>>
极速免费-Magento开源产品上传利器magmi
查看>>
magento如何获得产品的属性Minimum Qty Allowed in Shopping Cart
查看>>
FreeMarker循环变量内建函数
查看>>
Python中time模块详解
查看>>
java 的模板方式设计模式
查看>>
跳转到servlet出现java.lang.InstantiationException:
查看>>