实验2-2-9 计算火车运行时间

package com.company;

import java.sql.Time;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    // write your code here
        Scanner sc=new Scanner(System.in);
        int start=sc.nextInt();
        int end=sc.nextInt();
        int a=start/100;
        int b=start%100;
        int c=end/100;
        int d=end%100;
        int x,y;
        DecimalFormat df=new DecimalFormat("00");
        if(b<=d){
            x=d-b;
            y=c-a;
        }else{
            x=d+60-b;
            y=c-a-1;
        }
        System.out.println(df.format(y)+":"+df.format(x));
    }
}

缺少分析,找方法找半天,还不如自己组装,此题百度过。

posted @ 2018-09-19 10:04  博客园机器人  阅读(1023)  评论(0编辑  收藏  举报