题解 | #数组遍历#

数组遍历

https://www.nowcoder.com/practice/0f8219cb6f6e4e99a1bb0e868e51d60a

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int[] ary = new int[6];
        int max;
        int min;
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < ary.length ; i++) {
            ary[i] = scanner.nextInt();
        }
        for (int i = 0; i < ary.length; i++) {
            for (int j = 0; j < ary.length - 1; j++) {
                if (ary[j] > ary[j + 1]) {
                    int temp = ary[j];
                    ary[j] = ary[j + 1];
                    ary[j + 1] = temp;
                }
            }

        }
        min = ary[0];
        int b = ary.length;
        max = ary[b - 1];
        //write your code here......
        System.out.println(max + " " + min);
    }
}

用冒泡排序使数组进行排序,数组最后是最大的,第一个是最小的

全部评论

相关推荐

06-20 14:27
中山大学 C++
rt,day3就开始接需求
星际探神:你就想 你是水货他们都没面出来 他们也水 管他呢
点赞 评论 收藏
分享
05-09 14:45
门头沟学院 Java
点赞 评论 收藏
分享
在开会的单身狗很有一套:学院本被想着这么快有面试,而且简历废话太多了 那些在校经历什么荣誉什么的企业不关心
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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