题解 | #数组遍历#
数组遍历
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); }
}