為了計算看完課程要花多少時間做的
import java.util.Scanner; public class MainClass { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int second = 0; int minute = 0; while (true) { System.out.println("輸入分:"); int inM = sc.nextInt(); if (inM == -1) { break; } minute += inM; System.out.println("輸入秒:"); int inS = sc.nextInt(); minute += inS / 60; second += inS % 60; } int hour = minute / 60; minute += second/60; minute %= 60; System.out.println(hour + "小時" + minute + "分"); } }
全站熱搜
留言列表