题解 | #求最大最小数#

求最大最小数

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);
        }
    }
}
全部评论

相关推荐

2025-12-18 11:59
广州南方学院 C++
牛客78682892...:直接点还好,总比要了简历也不回的强
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务