📌  相关文章
📜  在数组列表中查找前 2 个值 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:26.338000             🧑  作者: Mango

代码示例1
public static void twoLargest(int values[]){

    int largestA = values[0];
    int largestB = -1;

    for(int i = 0; i < values.length; i++){

            if(values[i] > largestA){
                largestB = largestA;
                largestA = values[i];
            }
            else if (values[i] > largestB && values[i] != largestA) {
                largestB = values[i];
            }
    }
    System.out.println("Largest - " + largestA);
    System.out.println("2nd largest Largest - " + largestB);
}