if / else

์ฃผ์–ด์ง„ boolean ๊ฐ’์— ๋”ฐ๋ผ ๋ช…๋ น๋ฌธ ์‹คํ–‰ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •

package sec04.chap01;

public class Ex01 {
    public static void main(String[] args) {
        boolean open = true;
        int saleFrom = 10, saleTo = 20;
        int today = 15;

        //  ๐Ÿ’ก if : ๊ด„ํ˜ธ ์•ˆ์˜ boolean ๊ฐ’์ด true๋ฉด ๋‹ค์Œ ๋ช…๋ น ์‹คํ–‰
        if (open) System.out.println("์˜์—…์ค‘");
        if (!open) System.out.println("์˜์—…์ข…๋ฃŒ");

        //  ๐Ÿ’ก ์‹คํ–‰ํ•  ๋ช…๋ น์ด ํ•œ ์ค„ ์ด์ƒ์ผ ๊ฒฝ์šฐ ๋ธ”๋ก ์‚ฌ์šฉ
        if (today >= saleFrom && today <= saleTo) {
            System.out.println("์„ธ์ผ์ค‘์ž…๋‹ˆ๋‹ค.");
            System.out.println("์ „ํ’ˆ๋ชฉ 20% ํ• ์ธ");
        }
    }
}

Last updated