本帖最后由 李天富 于 2014-9-7 12:11 编辑
- import java.util.*;
- class timetest
- {
- public static void main(String[] args)
- {
- int time = new Scanner(System.in).nextInt();
- transTime(time);
- }
- public static void transTime(int num)
- {
- String[] unit={"天","时","分","秒"};
- int[] time=new int[4];
- int temp=0;
- time[0]=num/86400;
- temp=num%86400;
- time[1]=temp/3600;
- temp=temp%3600;
- time[2]=temp/60;
- time[3]=temp%60;
- for (int i=0;i<4 ;i++ )
- {
- if(i!=3&&time[i]==0)
- continue;
- System.out.print(time[i]+unit[i]);
- }
- }
- }
复制代码 简单写了下,就是不知道对于java来说,条件判断和做除法,哪个更为简洁。 |