JAVA

[생활코딩] 제어문 - 조건문

신동운 2024. 7. 2. 20:43

https://opentutorials.org/course/3975/26779

 

조건문 - 생활코딩

수업소개 조건에 따라서 다르게 동작하게 프로그램을 디자인하는 핵심은 조건문입니다. 조건문이라는 위대한 도구를 이용해서 우리의 프로그램을 더욱 지능적으로 만들어봅시다.  강의1 소스

opentutorials.org

 

public class IfApp {

 

public static void main(String[] args) {

 

System.out.println("a");

if(false) {

System.out.println(1);

}

System.out.println("b");

 

}

 

}

 

 

영원히 실행될 수 없는 코드 (if문의 조건에 false가 들어가는 문장) = dead코드라 오류 밑줄이 뜬다.

 

단일 블럭 ctrl + /

 

블럭 주석 ctrl + shift + /

 

 

public class IfApp {

 

public static void main(String[] args) {

 

System.out.println("a");

// if(false) {

// System.out.println(1);

// } else {

// if(true) {

// System.out.println(2);

// }

// else{

// System.out.println(3);

// }

// }

 

if(false) {

System.out.println(1);

} else if (true) {

System.out.println(2);

}

else{

System.out.println(3);

}

 

 

 

System.out.println("b");

 

}

 

}