3.18總結
今日上課
package b;
import java.util.Scanner;
public class b1 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.print("請輸入需要的陣列長度:");//0不可取..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
int number = in.nextInt();
int a[]=new int [number];
System.out.print("請輸入一個長度為"+number+"的陣列:");//負數不可取
for(int i=0;i<number;i++)
{
a[i]=in.nextInt();
}
int c=Largest(a, number);
System.out.println( c);
}
public static int Largest(int list[],int length) {
int i;
int max=list[0];
for(i=0;i<length-1;i++) {
if(list[i]>max)
{
max=list[i];
}
}
return max;
}
}