将秒数转换为时分秒的方法:
若秒数为sec,那么能够得到
- 时为sec/3600
- 分为sec%3600/60
- 秒为sec%3600%60
利用java实现:
import java.util.Scanner;
public class Time{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入要换算的秒数");
int sec = sc.nextInt(); //输入一个秒数
int h = sec / 3600;
int m = sec % 3600 / 60;
int s = sec % 60; //不足60的就是秒,够60就是分
System.out.println(h+"小时"+m+"分钟"+s+"秒");
}
}
利用c语言实现:
#include<studio.h>
int main()
{
int sec,h,m,s;
scanf("%d",&sec);
h=sec/3600;
m=sec%3600/60;
s=sec%3600%60;
printf("&d &d &d ",h,m,s);
return 0;
}