| 复制代码public class GetMax 
{
        public static void main(String[] args) 
        {
        int[] arr = { 5, 1, 6, 4, 2, 8, 9 };
        int V = getMax(arr);
        System.out.println(V);
        }
        public static int getMax(int[] arr)
        {
        int max = arr[0];
        for (int i = 0; i < arr.length; i++) 
        {
                if (arr[i] > max) 
                {
                        max = arr[i];
                }
        }
        return max;
        }
}
你这个代码应该是这个样子的吧,你可以这样理解,因为此时max结果为9,return就是返回,把max的结果返回去,那把他返还给谁呢,谁调用的他就反给谁,int V = getMax(arr)这里调用了,所以就把9返给V,所以V就等于9,然后输出来就完了。
 |