- import java.util.Scanner;
- public class Test3_Test {
- public static void main(String[] args) {
- int[] arr = new int[5];
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入数组的五个元素");
- for (int i = 0; i < arr.length; i++) {
- arr[i] = sc.nextInt();
- }
- int max = arr[0], min = arr[0];
- for (int i = 0; i < arr.length; i++) {
- System.out.println(arr[i]);
- if (max < arr[i]) {
- max = arr[i];
- }
- if (min > arr[i]) {
- min = arr[i];
- }
- }
- System.out.println("max=" + max + ",min=" + min);
- }
- }
复制代码 |
|