写一个程序,输入2个整数time1,time2,表示火车的出发时间和到达时间,计算并输出旅途时间。...

写一个程序,输入2个整数time1,time2,表示火车的出发时间和到达时间,计算并输出旅途时间。..._第1张图片

 

代码:

 1 import java.util.*;
 2 public class Main {
 3     public static void main (String [] args) {
 4         Scanner s=new Scanner(System.in);
 5         int time1=s.nextInt();
 6         int time2=s.nextInt();
 7         int hrs,mins;
 8         if(time2%100>=time1%100) {
 9             mins=time2%100-time1%100;
10             hrs=time2/100-time1/100;
11         }
12         else {
13             mins=time2%100+60-time1%100;
14             hrs=time2/100-1-time1/100;
15         }
16         System.out.println(hrs+" hrs "+mins+" mins");
17     }
18 }

 

转载于:https://www.cnblogs.com/fandehui/p/11050627.html

你可能感兴趣的:(c/c++,java,python)