课堂练习
代码
import java.util.*; public class danyuanceshi { static int Largest(int[] list,int length) { int i,max = list[0]; if(length==0||length<0) { return 0; } for(i=0;i<(length );i++) { if(list[i]>max) { max=list[i]; } } return max; } public static void main(String[] args) { int i; int[] list=new int[10]; Scanner input = new Scanner(System.in); System.out.println("请输入数组的长度:"); int length = input.nextInt(); System.out.println("请输入数组:"); for(i=0;i<length;i++) { list[i] = input.nextInt(); } System.out.println("最大数为:"+Largest(list,length)); } }
测试截图: