ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [30일코딩] 사칙연산과 논리연산
    개발입문/JAVA 2017. 5. 3. 21:02

    대수의 기본은 사칙연산 4개과 나머지(%) 이다.

    나머지는 나중에 자알~ 활용하는 값이 있으므로 알아만 놓자.


    그 외 논리연산자: 같음(등호), 같지않음(부등호), 큼/작음 등이있다.

    컴퓨터는 1 or 0 이나 같다/같지않다와 같이 이분법적으로 값을 인식한다.



    산술연산자 Arithmetic Operators

    Arithmetic Operators 
    The binary operators used for arithmetic are as follows:

    • +: Additive
    • -: Subtraction
    • *: Multiplication
    • /: Division
    • %: Remainder (modulo)





    논리연산자 Logical Operators

    Additional Operators

    • +: A binary operator used for String concatenation
    • ++: This unary operator is used to preincrement (increment by 1 before use) when prepended to a variable name or postincrement (increment by 1 after use) when appended to a variable.
    • --: This unary operator is used to predecrement (decrement by 1 before use) when prepended to a variable name or postdecrement (decrement by 1 after use) when appended to a variable.
    • !: This unary operator means not (negation). It's used before a variable or logical expression that evaluates to true or false.
    • ==: This binary operator is used to check the equality of 2 primitives.
    • !=: This binary operator is used to check the inequality of 2 primitives.
    • <><=>=: These are the respective binary operators for less thangreater thanless than or equal to, and greater than or equal to, and are used to compare two operands.
    • &&||: These are the respective binary operators used to perform logical AND and logical OR operations on two boolean (i.e.: true or false) statements.
    • ? : This ternary operator is used for simple conditional statements (i.e.: if ? then : else).





    DataType  Casting


    같은 숫자 int, double 끼리도 연산을 하다보면

    가장 호환범위가 넓은 데이터타입 으로 데이터타입이 변동된다.

    따라서 필요할 경우에는 연산결과의 데이터타입을 Casting (변환) 해야한다.







    출처 | https://www.hackerrank.com/challenges/30-operators/tutorial


    댓글

Designed by Tistory.