inblog logo
|
An's Blog
    JAVA

    [JAVA] 22. 계산기

    윤설안's avatar
    윤설안
    Feb 10, 2025
    [JAVA] 22. 계산기
    Contents
    문제1. 5 + 42. 결과 * 23. 결과 / 34. 결과 - 55. 최종 결과만 출력 (정답 : 1)

    문제

    1. 5+4
    1. 결과 * 2
    1. 결과 / 3
    1. 결과-5
    1. 최종 결과 값 출력

    1. 5 + 4

    package ex04; public class Cal01 { // 더하기 함수 static int add(int a, int b) { return a + b; } // 빼기 함수 static int sub(int a, int b) { return a - b; } // 곱하기 함수 static int mul(int a, int b) { return a * b; } // 나누기 함수 static int div(int a, int b) { return a / b; } public static void main(String[] args) { // 1. 5+4 int a = add(5, 4); System.out.println(a); } }
     

    2. 결과 * 2

    package ex04; public class Cal01 { // 더하기 함수 static int add(int a, int b) { return a + b; } // 빼기 함수 static int sub(int a, int b) { return a - b; } // 곱하기 함수 static int mul(int a, int b) { return a * b; } // 나누기 함수 static int div(int a, int b) { return a / b; } public static void main(String[] args) { // 문제 5+4, 결과 * 2, 결과 / 3, 결과-5(최종 결과 값 출력) // 1. 5+4 int a = add(5, 4); System.out.println(a); // 2. 결과 * 2 int b = mul(a, 2); System.out.println(b); } }

    3. 결과 / 3

    package ex04; public class Cal01 { // 더하기 함수 static int add(int a, int b) { return a + b; } // 빼기 함수 static int sub(int a, int b) { return a - b; } // 곱하기 함수 static int mul(int a, int b) { return a * b; } // 나누기 함수 static int div(int a, int b) { return a / b; } public static void main(String[] args) { // 문제 5+4, 결과 * 2, 결과 / 3, 결과-5(최종 결과 값 출력) // 1. 5+4 int a = add(5, 4); System.out.println(a); // 2. 결과 * 2 int b = mul(a, 2); System.out.println(b); // 3. 결과 / 3 int c = div(b, 3); System.out.println(c); } }

    4. 결과 - 5

    package ex04; public class Cal01 { // 더하기 함수 static int add(int a, int b) { return a + b; } // 빼기 함수 static int sub(int a, int b) { return a - b; } // 곱하기 함수 static int mul(int a, int b) { return a * b; } // 나누기 함수 static int div(int a, int b) { return a / b; } public static void main(String[] args) { // 문제 5+4, 결과 * 2, 결과 / 3, 결과-5(최종 결과 값 출력) // 1. 5+4 int a = add(5, 4); System.out.println(a); // 2. 결과 * 2 int b = mul(a, 2); System.out.println(b); // 3. 결과 / 3 int c = div(b, 3); System.out.println(c); // 4. 결과 -5 int d = sub(c, 5); // 최종 결과 값 System.out.println(d); } }

    5. 최종 결과만 출력 (정답 : 1)

    package ex04; public class Cal01 { // 더하기 함수 static int add(int a, int b) { return a + b; } // 빼기 함수 static int sub(int a, int b) { return a - b; } // 곱하기 함수 static int mul(int a, int b) { return a * b; } // 나누기 함수 static int div(int a, int b) { return a / b; } public static void main(String[] args) { // 문제 5+4, 결과 * 2, 결과 / 3, 결과-5(최종 결과 값 출력) // 1. 5+4 int a = add(5, 4); // 2. 결과 * 2 int b = mul(a, 2); // 3. 결과 / 3 int c = div(b, 3); // 4. 결과 -5 int d = sub(c, 5); // 최종 결과 값 System.out.println(d); } }
    notion image
    Share article
    Contents
    문제1. 5 + 42. 결과 * 23. 결과 / 34. 결과 - 55. 최종 결과만 출력 (정답 : 1)

    An's Blog

    RSS·Powered by Inblog