Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- super
- 조건문
- Overload
- After effects
- 형변환
- do while문
- 파라미터
- private
- if문
- Java
- Interface
- expand
- 변수
- length
- 배열
- Photoshop
- 메서드
- Override
- switch문
- illustrator
- 멤버변수
- for문
- symbol
- 생성자
- 상속
- Singleton
- static
- 반복문
- while문
- 클래스
Archives
- Today
- Total
Ms'Note
Object-4 본문
특정 기능을 목적으로 하는 메서드
- 메서드는 클래스 안에서 기능(동작)을 구현하기 위한 목적이다.
class Clac {
int plus(int x, int y) {
return x + y;
}
int minus(int x, int y) {
return x - y;
}
int times(intx, int y) {
return x * y;
}
int divide(int x, int y) {
int result = 0;
if(y != 0) {
// 0으로 나누기 불가능 하므로
result = x / y;
}
return result;
}
int f(int x, int y) {
int result = plus(x, y) + times(x, y);
return result;
}
}
public class Main04 {
public static void main(String[] args) {
Calc c = new Calc();
int p = c.plus(100, 50);
System.out.println("100+50=" + p);
int t = c.minus(100, 50);
System.out.println("100-50=") + t);
System.out.println("100*50=" + c.times(100,50));
System.out.println("100/50=" + c.divide(100, 50));
System.out.println("f(100,50)=" + c.f(100, 50));
}
}
출력 결과
100+50=150
100-50=50
100*50=5000
100/50=2
f(100,50)=5150
Comments