案例:数组最大值
//需求:设计一个方法用于获取数组中元素的最大值,调用方法并输出结果
public class HelloWorld {
public static void main(String[] args){
int arr[] = {
12,45,98,73,60};
int number = maxnumber(arr);
System.out.println(number);
}
public static int maxnumber(int arr[]){
int max = arr[0];
for (int x = 1;x < arr.length; x++){
if (arr[x]>max){
max = arr[x];
}
}
return max;
}
}