import java.util.InputMismatchException;import java.util.Scanner;
public class Max {
static int Largest(int list[],int length)
{
int i,max=list[0];
for(i=0;i<length;i++)
{
if(max<list[i])
max=list[i];
}
return max;
}
public static void main(String [] args)
{
try
{
Scanner in=new Scanner(System.in);
System.out.println("输入数组长度");
int length=in.nextInt();
int list[]=new int[length];
System.out.println("输入数组");
for(int i=0;i<length;i++)
{
list[i]=in.nextInt();
}
int max;
max=Largest(list,length);
System.out.println("最大值为"+max);
}
catch(InputMismatchException e)
{
System.out.println("输入错误");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("输入错误");
}
}
}
截图