public class MethodDemo04{
public static void main(String args[]){
System.out.println(add1(100,200)) ;
System.out.println(add2(100,200,300)) ;
System.out.println(add3(100.3f,200.6f)) ;
}
public static int add1(int i,int j){ // 定义了一个方法
int temp = 0 ; // 定义了一个临时的局部变量,方法执行完毕之后,此变量就消失了
temp = i + j ; // 执行加法操作
return temp ; // 把结果返回
}
public static int add2(int i,int j,int k){ // 定义了一个方法
int temp = 0 ; // 定义了一个临时的局部变量,方法执行完毕之后,此变量就消失了
temp = i + j + k ; // 执行加法操作
return temp ; // 把结果返回
}
public static float add3(float i,float j){ // 定义了一个方法
float temp = 0 ; // 定义了一个临时的局部变量,方法执行完毕之后,此变量就消失了
temp = i + j ; // 执行加法操作
return temp ; // 把结果返回
}
}