- public static void toTime() {
- int minutes = 0;
- int hours = 0;
- int days = 0;
- Scanner in = new Scanner(System.in);
- int seconds = 0;
- System.out.println("请输入一个整数(0表示退出)");
- while ((seconds = in.nextInt()) != 0) {
- days = seconds / (24 * 60 * 60);//获取天
- seconds %= (24 * 60 * 60);//得到获取天后的秒数
- hours = seconds / (60 * 60);//获取小时
- seconds %= (60 * 60);//得到获取小时后的秒数
- minutes = seconds / 60;//获取分钟
- seconds %= 60;//获取秒
- System.out.println((days == 0 ? "" : days + "天")
- + (hours == 0 ? "" : hours + "小时")
- + (minutes == 0 ? "" : minutes + "分")
- + (seconds == 0 ? "" : seconds + "秒"));
- }
- }
复制代码
我也刚刚走流程。希望可以帮到你理解一些 |