import java.util.Scanner;
class ArrayDemo
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("请你输入数组的长度");
int leg= scanner.nextInt();
int []array=new int[leg];
for (int ls=0;ls<leg ;ls++ ){
array[ls]=scanner.nextInt();
}
arrayErgodic(array);
int max=arrayMax(array);
System.out.println("数组的最大值是:"+max);
}
public static void arrayErgodic(int [] array){
for (int x =0 ;x<array.length ;x++ ){
System.out.print(array[x]+"\t");
}
}
public static int arrayMax(int [] array){
int max=0;
for (int x=0;x<array.length-1;x++ ){
if(array[x]>array[x+1]){
max=array[x];
} else {
max=array[x+1];
}
}
return max;
}
} |
|