![]() class Demo { public static void main(String[] args) { int[] arr={3,4,1,8}; int max=getMax(arr); System.out.println("max="+arr[max]); } public static int getMax(int[] arr) { int max=0; for (int x=1;x<=arr.length;x++ ) { if (arr[x]>arr[max]) max=x; } } } |
zhqw_heima 发表于 2015-3-25 13:29
你下面的getMax函数为何没有返回值,没返回值你如何获取最大值
向阳花 发表于 2015-3-25 18:51
返回值复制的时候漏掉了,代码是这样的:
运行结果是这样的:
zhqw_heima 发表于 2015-3-26 11:39
你这个提示是数组角标溢出异常,你 for (int x=1;x
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |