PAT (Basic Level) 1026 程序运行时间 (15分)JAVA解法

在这里插入图片描述

输入样例:

123 4577973

输出样例:

12:42:59




import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 
 
 
 
public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	float C1 = sc.nextFloat();
	float C2 = sc.nextFloat();
	float d = C2-C1;
	float t = d/100;
	int h = (int) (t/3600);
	t -= (h*3600);
	int m = (int) (t/60);
	t -= (m*60);
	t *= 10;
	  t += 5;
	  t /= 10;
	 int sec = 0;
	  sec = (int) t;
	 
        if (h < 10) {
            System.out.printf("0%d:",h);
            
        }else {
            System.out.printf("%d:",h);
        }
        
        if (m < 10) {
            System.out.printf("0%d:",m);
        }else {
            System.out.printf("%d:",m);
        }
        
        if (sec < 10) {
            System.out.printf("0%d",sec);
        }else {
            System.out.printf("%d",sec);
        }


	
	
	
	}
}

在这里插入图片描述

发布了83 篇原创文章 · 获赞 1 · 访问量 1033

猜你喜欢

转载自blog.csdn.net/qq_44028719/article/details/103986549
今日推荐