java
월 일로 이루어진 날짜를 2개 입력 받아, 두 번째 날짜가 첫 번째 날짜의 며칠째인지 출력하는 문제
반복문과 조건문을 활용해 문제를 풀었다.
어렵지 않게 해결한 문제
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
int[] daysInMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for(int test_case = 1; test_case <= T; test_case++)
{
int startMonth = sc.nextInt();
int startDay = sc.nextInt();
int endMonth = sc.nextInt();
int endDay = sc.nextInt();
int days = 0;
for (int month = startMonth; month <= endMonth; month++) {
if (month == startMonth) {
days += daysInMonth[month] - startDay + 1;
} else if (month == endMonth) {
days += endDay;
} else {
days += daysInMonth[month];
}
}
System.out.println("#" + test_case + " " + days);
}
}
}
Java테스트 시 의존성 주입(Dependency Injection)과 Mockito Spring 애플리케이션을 개발하다 보면, 테스트 코드에서 실제 빈(Bean)을 사용하지…
들어가며 스프링 기반 프로젝트에서 좋은 설계 구조와 테스트 전략은 소프트웨어 품질과 유지보수성에 직결됩니다. 최근 학습한…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…
Readable Code: 읽기 좋은 코드를 작성하는 사고법Practical Testing: 실용적인 테스트 가이드 강의와 함께한 인프런 워밍업 클럽…
들어가며 코드를 작성할 때 종종 "이 로직을 어떻게 단순하고 읽기 쉽게 표현할 수 있을까?" 고민하게…