我需要帮助才能获得数组中的最高值和最低值。我看到有些人使用Math.max
,Math.min
但你如何应用它?在这段代码中?
import java.util.Scanner;
public class CaseStudy2A {
public static void main(String[] args) {
Scanner inp = new Scanner (System.in);
int inpNum;
System.out.print("Enter Number: ");
inpNum = inp.nextInt();
int num[]=new int [inpNum];
int y=0;
int accu;
for(int x=0;x<inpNum;x++) {
y=y+1;
System.out.print("\nNumber [" + y + "] : ");
accu = inp.nextInt();
num[x]=accu;
}
for(int x=0;x<inpNum;x++)
System.out.print(num[x] + " ");
}
}