- import java.util.Scanner;
- public class TimeDemo {
- public static void main(String[] args) {
- System.out.println("请输入一个数字:");
- Scanner sc = new Scanner(System.in);
- int number = sc.nextInt();
-
- StringBuilder sb = new StringBuilder();
-
- int tian = number/(60*60*24);
- if(tian>0)
- sb.append(tian+"天");
- number = number%(60*60*24);
-
- int shi = number/(60*60);
- if(shi>0)
- sb.append(shi+"小时");
- number = number%(60*60);
-
- int fen = number/(60);
- if(fen>0)
- sb.append(fen+"分钟");
- number = number%60;
-
- if(number>0)
- sb.append(number+"秒");
-
- System.out.println(sb.toString());
- }
- }
复制代码 |