코딩배움일지/JAVA

JAVA 2일차 연산자

karatejin 2022. 11. 11. 11:58
public class LeapMonth {

    public static void main(String[] args) {

        int year =2000;

        String result = null;

        result = year % 4 ==0 && year % 100 != 0 || year % 400 == 0 ? "윤달입니다." : "윤달이 아닙니다.";

        System.out.println(year + ": " + result);

        /* 삼항연산자
        윤달의 조건
        4의 배수이고(and, &&) 100의 배수는 아니거나(!= 부정 || 이거나) 400의 배수(나누어 떨어진다)여야 윤달이다.
        
        2000 : 윤달입니다.
        1999 : 윤달이 아닙니다.
        */


    }

 

 

 

/*
  논리연산
  && (AND) - 곱
 * || (OR) - 합
 * ! (NOT) - 부정
 *
 * true (1)
 * false (0)

 true && true => true
 true && false -> false

 true || true => true
 true || false = true
 false || false = false

 !(true && true) = false

 */

public class Operation1 {

    public static void main(String[] args) {

        boolean a = 100 % 4 == 0;
        boolean b = false;
        System.out.println("<<<AND>>>");
        System.out.println( a && a);
        System.out.println( a && b);
        System.out.println( b && b);

        System.out.println("<<<OR>>>");
        System.out.println( a || a);
        System.out.println( a || b);
        System.out.println( b || b);
    }
}

 

 

 

public class Operation2 {

    public static void main(String[] args) {

        int num = 10;
        num = num +1;
        // ++num == 현재 num 에다가 1을 더해라  num++ == 원래  num 을 쓰고 다음에 더해라


        System.out.println(num++);
        System.out.println(num);

    }
}