题解 | #数组遍历#

数组遍历

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

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();}

    //write your code here......
    //冒泡排序的思想:设置最大最小值在数组中的标定,依次比较。
    max = ary[0];
    min = ary[ary.length-1]; 
    for(int j = 0;j<ary.length;j++){
        if(ary[j]>=max){
            max = ary[j];
        }
        if(ary[j]<=min){
            min = ary[j];
        }
    }
    System.out.println(max+" "+min);
}

}

全部评论

相关推荐

不亏是提前批,神仙打架,鼠鼠不配了
站队站对牛:现在92都报工艺岗了
投递韶音科技等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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