求学,哪位大Shen救救孩子!

1.定义一个int[]数组,里面最少有5个值,分别输出5个里面的最大值和最小值。
2.定义一个字符串数组,其中有最2个字符串的内容相同,将内容相同的字符串打印出来,并将其删除,再打印整个数组的内容。

1、数组排序一遍 再取最大下标和最小下标值 first()
2、迭代拿到重复值的下标,根据下标删除数组中的值 second()


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class Test1 {
    public static void main(String[] args) {
        second();
    }
    public static void second(){
        String[] arr = new String[]{"aa", "bb", "cc", "aa", "dd"};
        List<String> exist = new ArrayList<>();

        System.out.println("原数组:" + String.join(",", arr));
        int repeatIndex = -1;
        for (int i = 0; i < arr.length; i++) {
            String s = arr[i];
            if(exist.contains(s)){
                System.out.printf("重复:%s, 下标为:%s\n", s, i);
                repeatIndex = i;
            }
            exist.add(s);
        }

        if(repeatIndex > -1){
            String[] newArr = delIdx(arr, repeatIndex);
            System.out.println("新数组:" + String.join(",", newArr));
        }
    }

    public static String[] delIdx(String[] arr, int idx){
        if(idx > arr.length){
            throw new RuntimeException(String.format("数组越界; arr(%s) index(%s)", arr.length, idx));
        }

        String[] ret = new String[arr.length - 1];
        for (int i = 0; i < arr.length - 1; i++) {
            if(i >= idx){
                ret[i] = arr[i + 1];
            }else {
                ret[i] = arr[i];
            }
        }
        return ret;
    }

    public static void first(){
        int len = 5;
        int[] arr = new int[5];
        for (int i = 0; i < len; i++) {
            arr[i] = new Random().nextInt(10);
        }

        Arrays.sort(arr);
        System.out.printf("max: %s min:%s\n", arr[len - 1], arr[0]);
    }
}


这些问题不复杂,建议找个在线学习网站学习一下。