반응형

JAVA☕️
Beatcamp;
Theory01. 배열
HW01. 100일 후 날짜 계산기 (2가지)
Codeit;
[자바 왕기초] 05. 배열
05. 다중배열
오늘 늦잠을 자서 택시를 탔다. 택시를 타서 지각은 간신히 면할 수 있었지만... 앞으로는 무조건 7시 30분에 일어나는 습관을 만들어서 복습을 하고 강의를 들어야겠다. 휴🙄🙄🙄 정말! 제발! 늦게 자도 일찍 일어나자... Beatcamp; 2일동안 배열에 대해서 배우고 있는데 아직까지도 순간순간 헷갈린다. 책을 받았으니 반복해서 읽고 예제를 풀어봐야겠다. Codeit; DNA 염기 서열 분석 과제를 해결하려고 했는데 역시 배열문제여서 그런지 손가락을 움직일 수 없었다 💦💦 잠시 보류하고 JAVA의 정석📚을 읽고 돌아와서 다시 풀어봐야겠다.


TMI ) 강사님의 Today 띵언 : "20년 전 코딩을 배울 때는 컴퓨터가 비싸서 학원에 없었다. 따라서, 그림으로 그려서 집에가서 소스를 쓰고 코딩을 했다.", "나 스스로 컴파일러가 되야한다."
Beatcamp; HW01
public class Ch01Ex04 {
static int []days = new int []{31,28,31,30,31,30,31,31,30,31,30,31};
static int total = 0;
static Scanner scan = new Scanner(System.in);
static int month, day;
public static void main(String[] args) { // 1. total을 더해서 계산하는 방법
System.out.print("월 입력 >>> ");
month = scan.nextInt();
System.out.print("일 입력 >>> ");
day = scan.nextInt();
int total = 100;
int nextMonth = 0;
int nextDay = 0;
total = total - (days[month-1]-day);
int i = month;
while (total > days[i]){
total -= days[i];
i++;
}
nextMonth = i+1;
nextDay = total;
System.out.println("100일 후는 " + nextMonth + "월 " + (nextDay-1) + "일 입니다.");
}
public static void teset01(String[] args) { // 2. 100에서 해당 날짜를 빼서 계산하는 방법
// 월,일을 입력 받아서 100일 후의 날짜를 출력하는 프로그램.
System.out.print("월 입력 >>> ");
month = scan.nextInt();
System.out.print("일 입력 >>> ");
day = scan.nextInt();
int nextMonth = 0;
int nextDay = 0;
total = total + (days[month-1]-day);
int i = month;
while(total <100) {
total += days[i];
i++;
}
nextMonth = i;
nextDay = days[nextMonth] - (total - 100);
System.out.println("100일 후는 " + nextMonth + "월 " + nextDay + "일 입니다.");
}
}
반응형
'CodeSiri > TIL' 카테고리의 다른 글
| [TIL] 2021.01.21 (0) | 2021.01.21 |
|---|---|
| [TIL] 2021.01.20 (0) | 2021.01.20 |
| [TIL] 2021.01.18 (0) | 2021.01.18 |
| [TIL] 2021.01.17 (0) | 2021.01.17 |
| [TIL] 2021.01.16 (0) | 2021.01.16 |