求一组数的最大值

求一组数的最大值

public class HelloWorld{
    
    
    public static void main(String[] args){
    
    
        int arr[] = {
    
    12, 45,98,73,60};
        int max = arr[0];//一般都事将数组中的第一个数[0]当成初始值去与其他数据比较
        for (int x=1; x<arr.length; x++){
    
    
            if(arr[x] > max){
    
    
                max = arr[x];
            }
        }
        System.out.println("max:"+max);
    }
}

猜你喜欢

转载自blog.csdn.net/taoyingle/article/details/115116571