본문 바로가기

반응형

🕘 오전 수업 요약

✅ 1. for문 기본 사용

  • 1부터 10까지 출력:
for (int i = 1; i <= 10; i++) {
    System.out.print(i + "\t");
}

✅ 2. 1~100까지의 합 계산

  • 누적 합계:
int sum = 0;
for (int i = 1; i <= 100; i++) {
    sum += i;
}

✅ 3. 구구단 출력 (_99dan)

  • 중첩 for문 활용 (1~9단 출력)
  • System.out.printf()로 정렬
  • 3단마다 줄바꿈하여 보기 좋게 구성

✅ 4. while문 실습

  • i++을 이용한 1~10 출력
  • 1~100까지의 합계 계산

🕐 오후 수업 요약

✅ 1. do-while문

  • 조건보다 먼저 실행되는 반복문
  • "q" 입력 전까지 문자열 입력 반복

✅ 2. break 예제

  • 주사위를 던져 6이 나오면 반복 종료

✅ 3. continue 예제

  • 1~10 중 짝수만 출력 (홀수는 continue로 생략)

✅ 4. 실습 문제 (mission_34567)

3번 1~100 중 3의 배수의 합 출력
	static void mission3() {
		int sum = 0;

		for (int i = 1; i <= 100; i++)
			if (i % 3 == 0)
				sum += i;

		System.out.println("1~100 중 3의 배수의 합 : " + sum);
	}
4번 주사위 두 개의 합이 5가 될 때까지 반복 출력
	static void mission4() {
		int x, y;
		while (true) {
			x = (int) (Math.random() * 6) + 1;
			y = (int) (Math.random() * 6) + 1;
			if ((x + y) == 5)
				break;
			System.out.println("(" + x + ", " + y + ")");
		}
	}
5번 4x + 5y = 60을 만족하는 (x, y) 쌍 출력
	static void mission5() {
		for (int x = 0; x <= 10; x++) {
			for (int y = 0; y <= 10; y++) {
				if ((x * 4 + y * 5) == 60)
					System.out.println("(" + x + ", " + y + ")");
			}
		}
	}
6번 다음과 같은 별 출력 피라미드 구현
*
**
***
****
*****
	static void mission6() {
		for (int x = 1; x <= 5; x++) {
			for (int y = 1; y <= x; y++)
				System.out.print("*");
			System.out.println();
		}
	}
7번 간단한 ATM 프로그램
  • 메뉴: 예금 / 출금 / 잔고 확인 / 종료
  • 사용자 입력에 따라 동작 수행
	static void mission7() {
		Scanner sc = new Scanner(System.in);

		int money = 0;
		int select;

		while (true) {
			System.out.println("-------------------------------------");
			System.out.println("1. 예금 | 2. 출금 | 3. 잔고 | 4. 종료");
			System.out.println("-------------------------------------");

			System.out.print("선택> ");
			select = sc.nextInt();

			if (select == 1) {
				System.out.print("예금액> ");
				select = sc.nextInt();
				money += select;
			} else if (select == 2) {
				System.out.print("출금액> ");
				select = sc.nextInt();
				money -= select;
			} else if (select == 3) {
				System.out.println("잔고> " + money);
			} else
				break;

			System.out.println();
		}

		System.out.println("프로그램 종료");
	}

🧠 5일차 핵심 요약표

주제 내용
반복문 for, while, do-while
제어문 break, continue
누적 합 sum += 값 형태 사용
실습 중심 반복 + 조건문을 종합적으로 활용한 문제 풀이
사용자 입력 Scanner를 통한 값 입력 처리
댓글