CG 시스템 URL: http://211.81.175.89
메소드 오버로딩이란
[문제설명] 알려진 구분 함수 공식은 다음과 같다.
각 세분화 상황의 값을 계산하기 위해 4개의 오버로드된 f() 메서드가 포함된 Function 클래스를 정의합니다.
테스트 클래스를 정의하고 x, y 및 z 값의 입력, 조건 판단 및 결과 출력을 기본 메서드에서 구현합니다.
main 메서드는 다음과 같이 작성되었으며, main 코드를 수정하지 않도록 주의하세요. 수정하지 않으면 감점됩니다.
[입력형식] 세 개의 정수
[출력형식] 조각별 함수의 계산 결과를 나타내는 하나의 정수
[샘플 입력]
-1 5 7
【샘플 출력】
0
【샘플 입력】
2 -2 7
【샘플 출력】
4
import java.util.Scanner;
class Function{
public int f(){
return 0;
}
public int f(int x){
return x*x;
}
public int f(int x,int y){
return x*x+y*y;
}
public int f(int x,int y,int z){
return x*x+y*y+z*z;
}
}
public class two {
public static void main(String [] args){
int x,y,z;
Scanner in =new Scanner(System.in);
x=in.nextInt();
y=in.nextInt();
z=in.nextInt();
in.close();
Function function=new Function();
int result;
if(x<0){
result=function.f();
}
else if(x>=0 && y<0){
result=function.f(x);
}
else if(x>=0 && y>=0 && z<0){
result=function.f(x,y);
}
else{
result = function.f(x,y,z);
}
System.out.println(result);
}
}