java
CHAPTER 12 / 69
읽기 약 2분
SYNTAX
조건문/반복문
핵심 개념
if-else, switch-case로 분기 처리.
for, while, do-while, for-each로 반복.
Java의 for-each는 컬렉션 순회에 편리하다.
break/continue로 반복 흐름을 제어한다.
코드 분석
public class Control {
public static void main(String[] args) {
// if-else
int score = 85;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B"); // 출력
} else {
System.out.println("C");
}
// switch
String day = "MON";
switch (day) {
case "MON": System.out.println("월요일"); break;
case "FRI": System.out.println("금요일"); break;
default: System.out.println("기타");
}
// for
for (int i = 0; i < 5; i++) {
System.out.print(i + " "); // 0 1 2 3 4
}
// for-each
int[] nums = {10, 20, 30};
for (int n : nums) {
System.out.print(n + " "); // 10 20 30
}
}
}AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
Claude
무료: Sonnet 4.6 / Pro $20/mo: Opus 4.6
이 Spring '조건문/반복문' 코드에서 DI 관련 버그·순환 참조·트랜잭션 누수를 찾아서 수정해줘.
ChatGPT
무료: GPT-5.5 / Plus $20/mo: GPT-5.5 Pro
'조건문/반복문'를 Spring Boot 3.x로 구현한 실전 API 코드(컨트롤러+서비스+레포지토리+테스트)를 완성형으로 만들어줘.
Gemini
무료: 2.5 Flash / Pro $19.99/mo: 3.1 Pro
이 Spring '조건문/반복문' 프로젝트의 빈 구조와 의존성 트리를 전체 분석하고 N+1 쿼리·순환 참조·성능 병목을 정리해줘.
Grok
무료: Grok 4.1 / SuperGrok $30/mo
Spring '조건문/반복문' vs Quarkus·Micronaut·Ktor의 동일 기능 구현을 2026년 한국 채용 시장 기준으로 솔직히 비교해줘.
⭐ 이것만 기억하세요
조건문/반복문은 이 3가지만 확실히 잡으세요
1.JavaScript와 달리 Java의 switch는 문자열도 지원하지만, break를 빠뜨리면 fall-through가 발생합니다
2.if-else, switch(+enhanced switch), for, while, do-while — Java의 제어 흐름은 중괄호 기반 블록 스코프입니다
3.다음 챕터에서 배열과 동적 리스트를 배웁니다
공유하기
진행도 12 / 69