JAVA 기초 - 산술연산자(Arithmetic Operator)

2020. 5. 31. 14:09·JAVA/JAVA 기초

C_Arithmetic.java

package com.kh.operator;

// 산술연산자 (+ - * / %)
public class C_Arithmetic {
	
	public void method1() {
		int num1 = 10;
		int num2 = 3;
		
		//우선순위 : (* / %) > (+ -)
		
		System.out.println("num1 + num2 = " + (num1+num2));
		System.out.println("num1 - num2 = " + (num1-num2));
		System.out.println("num1 * num2 = " + num1*num2);
		System.out.println("num1 / num2 = " + num1/num2);
		System.out.println("num1 % num2 = " + num1 % num2);
	}
	public void method2() {
		int a = 5;
		int b = 10;
		int c = (++a) + b; // a=6, b=10, c=16
		int d = c / a; // a=6, b=10, c=16, d=2
		int e = c % a; // a=6, b=10, c=16, d=2 e=4
		int f = e++; // a=6, b=10, c=16, d=2 e=4(5) f=4
		int g = (--b) + (d--); //a=6, b=9, c=16 d=2(1) e=5 f=4 g=11
		int h = 2; // a=6, b=9, c=16 d=2(1) e=5 f=4 g=11 h=2
		int i = a++ + b / (--c / f) * (g-- - d) % (++e + h); //a=6(7), b=9, c=15, d=1 e=6 f=4 g=11(10) h=2 i=
		        // 6 + 9 /    3     *    10     %     8
				// 6 +   3          *    10     %     8
		        // 6 +            30            %     8
		        //  12
		
		// a=7, b=9, c=15, d=1, e=6, f=4, g=10, h=2, i=12
		System.out.println("a : " + a);
		System.out.println("b : " + b);
		System.out.println("c : " + c);
		System.out.println("d : " + d);
		System.out.println("e : " + e);
		System.out.println("f : " + f);
		System.out.println("g : " + g);
		System.out.println("h : " + h);
		System.out.println("i : " + i);
		
	}
}

 Point

- 후증감되는게 헷갈릴 수 있으니 주의 처리숫자 옆에 ()로 숫자 넣어 주기 ex. a=3(4)

'JAVA > JAVA 기초' 카테고리의 다른 글

JAVA 기초 - 논리연산자(Logical Operator)  (0) 2020.05.31
JAVA 기초 - 비교연산자(Comparison Operator)  (0) 2020.05.31
JAVA 기초 - 증감연산자(Increase & decrease Operators)  (0) 2020.05.31
JAVA 기초 - 논리부정연산자(Logical Negation)  (0) 2020.05.31
JAVA 기초 - Printf  (0) 2020.05.29
'JAVA/JAVA 기초' 카테고리의 다른 글
  • JAVA 기초 - 논리연산자(Logical Operator)
  • JAVA 기초 - 비교연산자(Comparison Operator)
  • JAVA 기초 - 증감연산자(Increase & decrease Operators)
  • JAVA 기초 - 논리부정연산자(Logical Negation)
꿀표
꿀표
양봉업자
  • 꿀표
    꿀로그
    꿀표
  • 전체
    오늘
    어제
    • 분류 전체보기 (82)
      • 인디해커 (0)
      • AI (0)
      • 프론트엔드 (34)
        • Javascript (17)
        • React (9)
        • Git (2)
        • Web Env (4)
        • Typescript (1)
        • 웹접근성 (1)
        • 상태관리 (0)
      • CS (8)
        • Network (3)
        • 알고리즘 (5)
      • 글쓰기 (3)
        • 생각 (2)
        • 서적 (1)
      • JAVA (37)
        • JAVA 기초 (22)
        • JSP (15)
  • 블로그 메뉴

    • 방명록
  • 인기 글

  • 태그

    network
    react
    그리디
    알고리즘
    구명보트
    프로그래머스
    js
    cross browsing
    greedy
    javascript
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
꿀표
JAVA 기초 - 산술연산자(Arithmetic Operator)
상단으로

티스토리툴바