/*
键盘输入6,打印6秒;
键盘输入60,打印1分;
键盘输入66,打印1分6秒;
键盘输入666,打印11分6秒;
键盘输入3601,打印1小时1秒
*/
import java.util.*;
class ShiJian {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
System.out.println("请输入数字");
int shuiZi = sc.nextInt();
String time ;
time = shiJian(shuiZi);
System.out.println(time);
}
public static String shiJian(int a){
int h = 0 ;
int m = 0 ;
int s = 0;
String time ;
if (a < 60) {
s = a ;
time = s + "秒";
}else if (a >= 60 && a < 3600) {
m = a / 60;
s = a - m * 60;
time = m + "分" + s + "秒" ;
}else if (a >= 3600 && a < 86400) {
h = a / 3600 ;
m = (a - h * 3600) / 60;
s = a - h * 3600 - m * 60;
time = h + "小时" + m + "分" + s + "秒" ;
}else {
time = "无法计算该时间";
}
return time ;
}
}
|
|