package com.test;
import java.util.Scanner;
/**
* 3、 从键盘接受一个数字,打印该数字表示的时间,最大单位到天,例如: 键盘输入6,打印6秒; 键盘输入60,打印1分; 键盘输入66,打印1分6秒;
* 键盘输入666,打印11分6秒; 键盘输入3601,打印1小时1秒
*/
public class Test2 {
public static void main(String[] args) {
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(3600*24<=mun){
day = mun/(3600*24);
mun = mun - day * 3600*24;
System.out.print(""+day+"天");
}
if (mun >= 3600) // 判断小时
{
hour = mun / 3600;
mun = mun - hour * 3600;
System.out.print(""+hour+"时");
}
if (mun >= 60) // 判断分钟数
{
minute = mun / 60;
mun = mun - minute * 60;
System.out.print(""+minute+"分");
}
System.out.println(mun+"秒");
} else {
System.out.print(" ");
}
}
}
|
|