虽然论坛有了但也是我自己独立写的;
- public class day26 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int time = sc.nextInt();
- int tian =0;//天
- int shi = 0;//时
- int fen = 0;//分
- int miao = 0;//秒
- /* if(time>=86400){ //一天86400秒
- tian = time/86400;
- }
- if(tian>=0){
- shi =(time%86400)/3600;
- }
- if(shi>=0){
- fen = (time%86400%3600)/60;
- }
- if(fen>=0){
- miao = time%86400%3600%60;
- }
- System.out.println(tian+"天"+shi + "时" + fen + "分" + miao + "秒");*/
- if(time>=86400){<span style="line-height: 30.7999992370605px;">//如果大于一天走这里,一天86400秒</span>
- tian = time/86400;//因为是int型所以除以一天的秒数就得到天数
- shi = time%86400/3600;//模以秒数就剩下不到一天的秒数,再除以一小时的秒数就得到时
- fen = time%86400%3600/60;//道理同上
- miao = time%86400%3600%60;//道理同上
- }
- if(time>=3600&&time<86400){//超过小时但不到一天走这里
- shi = time%86400/3600;
- fen = time%86400%3600;
- miao = time%86400%3600%60;
- }
- if(time>=60&&time<3600){//不到一小时走这里
- fen = time/60;
- miao = time%60;
- }
- if(time>0&&time<60){
- miao = time;
- }
- System.out.println(tian+"天"+shi + "时" + fen + "分" + miao + "秒");
- }
- }
复制代码
第一种方法做出来测试了下没有错误但是感觉应该会有问题,所以后面自己改进了一下。于是有了第二种方法。
|
|