Java 19-方法 参数

 

1、参数列表和返回值

public static void function(int num){//形参
System.out.println("传入的参数是:"+num);
}
public static void main(String[] args) {
function(3);//实参
}

 

public static void function3(int[] scores){
int sum = 0;
for (int x:scores){
sum = sum+x;
}
double avg = sum*1.0/(scores.length);
System.out.println(avg);
}

public static void main(String[] args) {
int [] ss = {89,90,91,82,98};
function3(ss);
}
posted @ 2021-12-28 16:05  小小生Sir  阅读(24)  评论(0编辑  收藏  举报