public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int d = x/24/60/60;
int h = (x-d*24*60*60)/(60*60);
int m = (x-d*24*60*60-h*60*60)/60;
int s = x%60;
if (d > 0 ) {
System.out.println(d+"天"+h+"小时"+m+"分"+s+"秒");
}else if(h>0){
System.out.println(h+"小时"+m+"分"+s+"秒");
}else if (m>0) {
System.out.println(m+"分"+s+"秒");
}else{
System.out.println(s+"秒");
}
} 作者: qq331335030 时间: 2015-11-23 15:51
刚才那个有点问题,这个应该没问题了,我也是菜鸟哦,调试了好几次的,呵呵
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int d = x/24/60/60;
int h = (x-d*24*60*60)/(60*60);
int m = (x-d*24*60*60-h*60*60)/60;
int s = x%60;
if (d > 0 )
System.out.print(d+"天");
if(h>0)
System.out.print(h+"小时");
if (m>0)
System.out.print(m+"分");
if (s>0)
System.out.print(s+"秒");
}