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);
}
}

Share article