Ranking in Array


Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

設計一程式,讓使用者輸入5個整數,並存放於陣列(array)中,最後將前三大的數值分別改為(由大到小): 1st 2nd 3rd 後輸出陣列中的值。

樣板程式碼如下

import java.util.Scanner;import java.util.Scanner;

public class Rank {

    public static void main(String[] args) {

        int[] nums = new int[5];
        String[] rank = new String[5];

        Scanner input = new Scanner(System.in);

        String[] s = { "1st", "2nd", "3rd" };

        //TODO:請補齊剩下的程式碼。
    }

    public static int maxIndex(int[] nums)  {

       //TODO:請補齊剩下的程式碼。

    }
}

輸入值的格式

  • 輸入5個整數,各數字之間以空白隔開。

  • 輸入的數值皆不會有負數與重複值。

輸出值的格式

  • 將前三大的數值依序取代為:1st 2nd 3rd

sample input1

10 50 30 20 40

sample output1

10 1st 3rd 20 2nd

sample input2

1 2 3 4 5

sample output2

1 2 3rd 2nd 1st

Comments

There are no comments at the moment.