Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

변수 사용 이유 본문

Java/JAVA1

변수 사용 이유

빌드이너프 2023. 5. 14. 12:01

이 코드에서 사칙연산을 변경하고 싶은 경우 하나씩 숫자를 바꿔줘야 한다

public class practice {
    public static void main(String[] args) {
        System.out.println(6+3);
        System.out.println(6-3);
        System.out.println(6*3);
        System.out.println(6/3);
    }
}

 

변수 x와 y를 설정하면 언제든지 원하는 값으로 변경해 줄 수 있다

public class practice {
    public static void main(String[] args) {
        int x = 4;
        int y = 2;
        System.out.println(x+y);
        System.out.println(x-y);
        System.out.println(x*y);
        System.out.println(x/y);
    }
}

'Java > JAVA1' 카테고리의 다른 글

printf(), toBinaryString()  (0) 2023.05.14
기본형(Primitive type)  (0) 2023.05.14
두 변수의 값 교환  (0) 2023.05.14
변수(variable), 상수(constant), 리터럴(literal)  (0) 2023.05.14
변수의 타입  (0) 2023.05.14