day10_MyMathTestEx02

육희영·2021년 10월 26일
0
package com.java1.day10;

public class MyMathTestEx02 {

	public static void main(String[] args) {
		MyMath mm = new MyMath();
		long result1 = mm.add(5L, 3L);
		long result2 = mm.subtract(5L, 3L);
		long result3 = mm.multiply(5L, 3L);
		double result4 = mm.divide(5L, 3L); // double대신 long값을 입력했다.
		
		int result5 = mm.min(10, 5);

		System.out.println("add(5L, 3L) = " + result1); // 더하기
		System.out.println("subtract(5L, 3L) = " + result2); // 빼기
		System.out.println("multiply(5L, 3L) = " + result3); // 곱하기
		System.out.println("divide(5L, 3L) = " + result4); // 나누기
		
		System.out.println("min(10, 5) = " + result5); // 빼기

	}
}

class MyMath {
	long add(long a, long b) { 
		long result = a+b;
		return result;
		//return a + b; // 위의 두 줄을 이와 같이 한 줄로 간단히 할 수 있다.
	}

	long subtract(long a, long b) {
		return a - b;
	}

	long multiply(long a, long b) {
		return a * b;
	}

	double divide(double a, double b) { // long 을 double 로 자동 형변환
		return a / b;
	}
	int min(int a, int b) {
		return a - b;
	}
}

출력결과

add(5L, 3L) = 8
subtract(5L, 3L) = 2
multiply(5L, 3L) = 15
divide(5L, 3L) = 1.6666666666666667
min(10, 5) = 5

0개의 댓글

관련 채용 정보