Exercise(Java)

NasK!m_311Β·2022λ…„ 8μ›” 9일
0

Exercise

λͺ©λ‘ 보기
1/5
post-thumbnail

πŸ’‘ 쑰건문 λ¬Έμ œν’€μ΄

package day04;

import java.util.Scanner;

public class Baekjoon {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in); 		// μž…λ ₯λ°›κΈ° μœ„ν•΄ Scannerλ₯Ό 써쀀닀.

		System.out.print("ν˜„μž¬ μ‹œ : "); 				// ν˜„μž¬μ‹œκ°μ„ μž…λ ₯λ°›λŠ”λ‹€.
		int a = sc.nextInt(); 						// (0 <= a <= 23)
		System.out.print("ν˜„μž¬ λΆ„ : "); 				// ν˜„μž¬μ‹œκ°μ„ μž…λ ₯λ°›λŠ”λ‹€.
		int b = sc.nextInt(); 						// (0 <= b <= 59)

		System.out.print("κ±Έλ¦¬λŠ” μ‹œκ°„ : "); 			// μš”λ¦¬ν•˜λŠ”λ° κ±Έλ¦¬λŠ” μ‹œκ°„μ„ μž…λ ₯λ°›λŠ”λ‹€.(λΆ„ λ‹¨μœ„λ‘œ)
		int c = sc.nextInt(); 						// (0 <= c <= 1000)

		int resA = a + (c / 60); 					// μš”λ¦¬ ν›„ μ‹œκ°„μ˜ μ‹œκ°ν‘œμ‹œλ₯Ό λ³€μˆ˜ μ„ μ–Έ
		int resB = b + (c % 60); 					// μš”λ¦¬ ν›„ μ‹œκ°„μ˜ λΆ„ν‘œμ‹œλ₯Ό λ³€μˆ˜ μ„ μ–Έ
		String msg = "μš”λ¦¬ 끝!!"; 					// μš”λ¦¬ λλ‚˜μ„œ μ‹ λ‚œ 메세지 좜λ ₯ λ³€μˆ˜ μ„ μ–Έ

		if (a >= 0 && a <= 23 && b >= 0 && b <= 59 && c >= 0 && c <= 1000) { // a,b,c의 λ²”μœ„ μ„€μ •.

			if (resA >= 0 && resA <= 23) { 			// μš”λ¦¬ 끝났을 λ•Œ μ‹œκ°ν‘œμ‹œκ°€ 24λ₯Ό λ„˜μ§€ μ•Šμ•˜μ„ λ–„
				if (resB >= 0 && resB <= 59) { 			// μš”λ¦¬ 끝났을 λ•Œ μ‹œκ° ν‘œμ‹œκ°€ 24λ₯Ό λ„˜μ§€ μ•Šκ³ , λΆ„ν‘œμ‹œκ°€ 60을 μ•ˆλ„˜μ„ λ–„
					System.out.println(msg);
					System.out.println(resA + "μ‹œ " + resB + "λΆ„");
				} else if (resB >= 60) { 				// μš”λ¦¬ 끝났을 λ•Œ μ‹œκ° ν‘œμ‹œκ°€ 24λ₯Ό λ„˜μ§€ μ•Šκ³ , λΆ„ν‘œμ‹œκ°€ 60을 λ„˜μ„ λ–„
					if ((resA + 1) <= 23) { 				// μš”λ¦¬λλ‚œ μ‹œκ° + 1이 24λ₯Ό λ„˜μ§€ μ•Šμ„ λ•Œ
						System.out.println(msg);
						System.out.println((resA + 1) + "μ‹œ " + (resB - 60) + "λΆ„");
					} else { 								// μš”λ¦¬ λλ‚œ μ‹œκ° + 1이 24λ₯Ό λ„˜μ„ λ•Œ
						System.out.println(msg);
						System.out.println("0μ‹œ " + (resB - 60) + "λΆ„");
					}
				}
			
            } else if (resA >= 24) { 				// μš”λ¦¬ 끝났을 λ•Œ μ‹œκ°ν‘œμ‹œκ°€ 24λ₯Ό λ„˜μ—ˆμ„ λ•Œ
				if (resB >= 0 && resB <= 59) { 			// μš”λ¦¬ 끝났을 λ•Œ μ‹œκ° ν‘œμ‹œκ°€ 24λ₯Ό λ„˜κ³ , λΆ„ν‘œμ‹œκ°€ 60을 μ•ˆλ„˜μ„ λ–„
					System.out.println(msg);
					System.out.println((resA - 24) + "μ‹œ " + resB + "λΆ„");
				} else if (resB >= 60) { 				// μš”λ¦¬ 끝났을 λ•Œ μ‹œκ° ν‘œμ‹œκ°€ 24λ₯Ό λ„˜κ³ , λΆ„ν‘œμ‹œκ°€ 60을 λ„˜μ„ λ–„
					System.out.println(msg);
					System.out.println((resA - 23) + "μ‹œ " + (resB - 60) + "λΆ„");
				}
			}
            
		} else {
			System.out.println("μ‹œκ°„ λͺ¨λ₯΄λƒγ…‘γ…‘;");
		}
	} // main λ©”μ†Œλ“œ λ‹«λŠ” μ€‘κ΄„ν˜Έ
} // baekjoon 클래슀 λ‹«λŠ” μ€‘κ΄„ν˜Έ
profile
메리아빠, λ¨Ήλ‹€κ°€ 죽어도 λ˜λŠ” 개발자.(μ‚΄λΊ΄μž....)

0개의 λŒ“κΈ€