- package demo3;
- import java.util.Scanner;
- public class Test5 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- //输入数字
- int num = sc.nextInt();
- if (num < 0) {
- System.out.println("非法参数");
- }else if(num<60){
- second(num);
- }
- else if (num < 3600) {
- //数字没有到3600
- minute(num);
- } else {
- //数字到3600秒或者以上
- hour(num);
- }
- }
- private static void second(int num) {
- //输出秒的文本
- int s=num%60;
- System.out.println(s+"秒");
- }
- private static void minute(int num) {
- //输出分秒的文本
- int m = num / 60;
- int s = num % 60;
- System.out.println(m + "分" + s + "秒");
- }
- private static void hour(int num) {
- //输出时分秒的文本
- int h = num / 3600;
- int m = num % 3600 / 60;
- int s = num % 3600 % 60;
- System.out.println(h + "时" + m + "分" + s + "秒");
- }
- }
复制代码 这就是代码咯,欢迎互顶
|