if 문

조건식이 true일 때, 괄호{} 안의 문장들을 수행

if (조건식) {

}

 

블럭{} 내의 문장이 하나뿐인 경우 {} 생략 가능

public class practice {
    public static void main(String[] args) {
        if (3 > 1)
            System.out.println(3); // 3
    }
}

 

가능하면 {} 생략하지 않고 사용하기

public class practice {
    public static void main(String[] args) {
        if (3 > 1) {
            System.out.println(3); // 3
        }
    }
}
반응형

'이것이 자바다 > JAVA1' 카테고리의 다른 글

If-else 문  (0) 2023.05.17
조건식  (0) 2023.05.17
복합 대입 연산자 +=  (0) 2023.05.17
조건 연산자 ? :  (0) 2023.05.17
문자열 비교 equals()  (0) 2023.05.16

+ Recent posts