题解 | #求最大最小数#
求最大最小数
http://www.nowcoder.com/practice/82e5ff335eeb486aab359767895cc7b4
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
int max=Integer.MIN_VALUE,min=Integer.MAX_VALUE;
for (int i = 0; i < n; i++) {
int anInt = scanner.nextInt();
if(anInt>max){
max=anInt;
}
if(anInt<min){
min=anInt;
}
}
System.out.println(max+" "+min);
}
}
}
查看11道真题和解析