- package com.itheima;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.util.Scanner;
- /*
- * 第一题:从键盘接受一个数字,打印该数字表示的时间,最大单位到天
- 例如:
- 键盘输入6,打印6秒
- 键盘输入60,打印1分
- 键盘输入66,打印1分6秒
- 键盘输入666,打印11分6秒
- 键盘输入3601,打印1小时1秒
- 键盘输入86440,打印1天40秒
- */
- public class Test1 {
- public static void main(String[] args) throws IOException {
- Scanner sss = new Scanner(System.in);
- System.out.print("请输入秒数::");
- int mun ,second,minute,hour,day,n;
- mun = sss.nextInt();
- System.out.print("键盘输入"+mun+".......打印:");
-
-
- if(mun >0){
- if(mun >=86400) //判断天数
- {
- day = mun/86400;
- mun= mun- day * 86400 ;
- System.out.print(day+"天");
- }
-
- if(86400>mun && mun>=3600) //判断小时
- {
- hour = mun/3600;
- mun = mun -hour*3600;
- System.out.print(hour+"时间");
- }
-
- if(3600>mun && mun>=60) //判断分钟数
- {
- minute = mun/60;
- mun = mun -minute*60;
- System.out.print(minute+"分钟"); }
-
- if(60>mun && mun>0) //判断秒
- {
- second = mun;
-
- System.out.print(second+"秒");
- }
- }else{
- System.out.print("输入的值不对");
- }
-
-
- }
- }
复制代码
|