- package Test_53;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- // System.out.println(60*60*24*365);
- Scanner sc = new Scanner(System.in);
- System.out.println("输入数字:");
- method(sc.nextInt());
- }
- private static void method(int in) {
- //定义键盘录入的字符串长度,之所以为笨方法,就是从判断输入的字符长度开始
- int index = String.valueOf(in).length();
- int num = 60;
-
- //判断秒
- if (index == 1 || index == 2) {
- if(in>0 &&in < num){
- System.out.println(in+"秒");
- }
- }
- //判断分秒
- if(index == 2 || index == 3 || index == 4){
- if(in >= num && in<num*num){
- int fen = in/num;
- int miao = in%num;
- System.out.println(fen+"分"+miao+"秒");
- }
- }
- //判断时分秒
- if(index == 4 || index == 5){
- if(in >= num*num && in<num*num*24){
- int xs = in/(num*num);
- int temp = in%(num*num);
- int fen = temp/num;
- int miao = temp%num;
- System.out.println(xs+"小时"+fen+"分"+miao+"秒");
- }
- }
- //判断天时分秒
- if(index >= 5 && index <= 8){
- if(in >=num*num*24 && in <= num*num*24*365){
- int tian = in/(num*num*24);
- int temp1 = in%(num*num*24);
- int xs = temp1/(num*num);
- int temp = in%(num*num);
- int fen = temp/num;
- int miao = temp%num;
- System.out.println(tian+"天"+xs+"小时"+fen+"分"+miao+"秒");
- }
- }
- }
- }
复制代码 |