package priv.cy.time;
import java.util.Scanner;
public class TimeTest {
public static void main(String[] args) {
while (true) {//先搞一个死循环
System.out.println("输入数字:");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
if (num < 0 || num >86400) {//当输入不符合要求是退出循环
System.out.println("输入结果不符合要求!");
break;
} else if (num >= 0 & num < 60) {
System.out.println(num + "秒");
} else if (num < 3600) {
System.out.println(num / 60 + "分" + num % 60 + "秒");
} else if (num <= 86400) {
int hour = num / 3600;//计算小时
int min = num % 3600 / 60;//计算分钟
int sec = num - hour * 3600 - min * 60;//秒
System.out.println(hour + "小时" + min + "分" + sec + "秒");
}
}
}
}
|