How can I locate and print the index of a max value in an array?

前端 未结 2 2092
遇见更好的自我
遇见更好的自我 2020-12-11 03:09

For my project, I need to make a program that takes 10 numbers as input and displays the mode of these numbers. The program should use two arrays and a method that takes arr

2条回答
  •  再見小時候
    2020-12-11 04:01

    You could change last part to:

    int maxIndex = 0;
    for (int i = 0; i < modetracker.length; i++) {
        if (modetracker[i] > max) {
            max = modetracker[i];
            maxIndex = i;
        }
    }
    System.out.println(maxIndex);
    

提交回复
热议问题