public class Test02 {
public static void main(String[] args) { //函数
// 函数调用的时候传递的参数叫实际参数
int a1 = 100;
int a2 = 200;
int max = a1;
if (max < a2) {
max = a2;
}
hello();
System.err.println("bye");
}
//可以完成特定功能的代码块,并且能重复调用
//返回值 函数名 参数列表 函数体
public static void hello() {
System.out.println("hello");
}
public static void println(int x) {
System.err.println(x);
}
public static double PI() {
return 3.1415926;
}
//定义函数的时候,参数叫型=形参数
public static int max(int x1, int x2) {
if (x1 > x2) {
return x1;
}
return x2;
}
//函数名相同,参数不同,函数重载overload
//函数名可以相同,但参数不能也相同
//函数的的签名,(参数类型) max(float, float)
//函数的签名不能相同
public static float max1(float x1, float x2) {
if (x1 > x2) {
return x1;
}
return x2;
}
public static float max(float y1, float y2) {
if (y1 > y2) {
return y1;
}
return y2;
}
}