Java 数组马拉松程序

问题描述 投票:0回答:0

编写一个方法,将一个整数数组作为输入并返回一个整数。将时间数组传递给 这个方法。返回值应该是时间最少的人对应的索引。 然后,您可以使用 main 中返回的整数对两个数组进行索引,以同时获取名称和 时间。打印出返回索引对应的名称和时间。您必须将 printf 与 formatting 格式化输出。 编写第二种方法来查找第二快时间的索引。第二种方法应该使用 第一种方法确定最佳跑步者,然后遍历所有值以找到第二好的 (倒数第二)时间。 到目前为止,我得到了什么,但我不确定我是否在正确的轨道上,关于我的代码的一些建议和反馈以及类似的例子会有帮助吗?

公开课马拉松{ public static void main(String[] arguments) {

    String[] names = {
        "Elena",
        "Thomas",
        "Hamilton",
        "Suzie",
        "Phil",
        "Matt",
        "Alex",
        "Emma",
        "John",
        "James",
        "Jane",
        "Emily",
        "Daniel",
        "Neda",
        "Aaron",
        "Kate"
    };

    int[] times = {
        341,
        273,
        278,
        329,
        445,
        402,
        388,
        275,
        243,
        334,
        412,
        393,
        299,
        343,
        317,
        265
    };

    //int fastestIndex;
    //int secondFastestIndex;

    int i1 = fastestIndex(times); // i1 is the index of the fastest runner
    // You need to use i1 to computer index of the second fastest runner
    int i2 = secondFastestIndex(times, i1);
    /*
    //ADD YOUR CODE HERE TO PRINT THE RESULTS %2.2f\n       for (int value : array)
    //System.out.printf("   %d", value);
    //      System.out.printf(
    "Effects of passing reference to entire array:%n" 
    "The values of the original array are:%n");
    //System.out.printf("%-20s %4d\n", "spacing right", 45 );
    */
    System.out.printf("Fastest Runner: %-20s %4d\n " + "spacing right", 45, i);
    System.out.printf("Seconded Fastest Runner: %-20s %4d\n " + "spacing right", 45, i1);

}
//public static boolean determineIfPrime(int nm
//WRITE THE TWO METHODS, getFastestIndex AND getSecondFastestIndex, HERE
//The fastest runner is:       John 
public static boolean getFastestIndex(int[] times) {
        for (int i = 0; i < times.length; i++) {
            if (max < times[i]);
            Index = i;
        }
        public static boolean getSecondFastestIndexFastestIndex(int[] times) {
            for (int i1 = 0; i1 < times.length; i1++) {
                if (max < times[i1]);
                Index = i1;
            }
        }
arrays methods marathon
© www.soinside.com 2019 - 2024. All rights reserved.