方法
定义方法
- 方法(函数):为了完成某个功能的代码片段
public :方法的访问权限修饰符
static:不是必须的静态方法
void: 代表返回值类型 void表示方法无返回值
/*
*如果写的是某个数据类型,那么方法中一定要return,使用return返回值
* 求三个数最值
public static int Cmpmax(int a, int b , int c){
int max1 = a > b ? a : b;
int max = max1 > c ? max1 : c;
return max;
}
方法的调用
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
System.out.println(Cmpmax(a,b,c));
}