자바 백준 5554번
브론즈 4
https://www.acmicpc.net/problem/5554
문제 보기

분류: 수학, 구현, 사칙연산
코드 풀이
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 총 이동 시간을 계산하기 위한 메서드를 호출 int totalTimeInSeconds = getTotalTravelTime(sc); // 계산된 총 이동 시간을 분과 초로 출력하는 메서드를 호출 printTravelTime(totalTimeInSeconds); } // 이동 시간을 입력받아 총 이동 시간을 초 단위로 계산하는 메서드 private static int getTotalTravelTime(Scanner sc) { // 각 이동 시간(초 단위)을 입력 int timeToSchool = sc.nextInt(); // 집에서 학교까지의 이동 시간 int timeToPCBang = sc.nextInt(); // 학교에서 PC방까지의 이동 시간 int timeToAcademy = sc.nextInt(); // PC방에서 학원까지의 이동 시간 int timeToHome = sc.nextInt(); // 학원에서 집까지의 이동 시간 // 모든 이동 시간을 합산하여 반환 return timeToSchool + timeToPCBang + timeToAcademy + timeToHome; } // 총 이동 시간을 분과 초로 변환하여 출력하는 메서드 private static void printTravelTime(int totalTimeInSeconds) { // 총 시간을 분과 초로 변환 int minutes = totalTimeInSeconds / 60; // 총 분 int seconds = totalTimeInSeconds % 60; // 총 초 // 변환된 분과 초를 각각 출력 System.out.println(minutes); System.out.println(seconds); } }
'공부하기 > 백준' 카테고리의 다른 글
[Java] 백준 풀기 17608 - 막대기 (2) | 2024.12.08 |
---|---|
[Java] 백준 풀기 4458 - 첫 글자를 대문자로 (0) | 2024.11.26 |
[Java] 백준 풀기 5724 - 파인만 (0) | 2024.10.12 |
[Java] 백준 풀기 11282 - 한글 (0) | 2024.10.09 |
[Java] 백준 풀기 3085 - 사탕 게임 (2) | 2024.09.07 |