[자바 알고리즘] 59. 시계연산 (분과 초 연산)

김건우's avatar
Feb 14, 2025
[자바 알고리즘] 59. 시계연산 (분과 초 연산)
package Test01; import java.util.Scanner; // 총 초를 입력받아 분과 초로 변환하는 함수 public class Time01 { public static void time(int total) { // 분은 총 초를 60으로 나눈 몫 int minutes = total / 60; // 초는 총 초를 60으로 나눈 나머지 int seconds = total % 60; // 결과 출력 System.out.println("총 " + total + "초는 " + minutes + "분 " + seconds + "초 입니다."); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // 사용자로부터 총 초를 입력받기 System.out.print("총 초를 입력하세요: "); int totalSeconds = scanner.nextInt(); // 변환 함수 호출 time(totalSeconds); } }
notion image
Share article

gunwoo