JAVA

[점프 투 자바] if 문

explorer999 2024. 2. 1. 18:03
import java.util.ArrayList;
 

public class Sample5 {
    public static void main(String[] args) {
        int money = 2000;
        boolean hasCard = true;
        if (money >= 3000) {
            System.out.println("택시를 타고 가라");
        }else {
            System.out.println("걸어가라");
        }

    /*
     * && = and
     * || = or
     * !  = not
     */
 
 
 
 

        if (money>=3000 || hasCard) {
            System.out.println("택시를 타고 가라");
        }else {
            System.out.println("걸어 가라");
        }
        //돈이 3000원 이상 있음 or 카드가 있음 ==> 택시를 타고 가라
 
 
 
 
 

        ArrayList<String> pocket = new ArrayList<String>();
        pocket.add("paper");
        pocket.add("headphone");
        pocket.add("money");

        if (pocket.contains("money")) {
            System.out.println("택시를 타고 가라");
        }else {
            System.out.println("걸어가라");
        }
 
 
 
 
 

        if (pocket.contains("money")) {
            System.out.println("택시를 타고 가라");
        }else if (pocket.contains("card")) {
            System.out.println("택시를 타고 가라");
        }else {
            System.out.println("걸어 가라.");
        }

    }
}