The example in this article tells the Java implementation to give an array of fractional arrays to the corresponding ranking. Share to everyone for your reference. The implementation method is as follows:
package test01;/** * give the fractional array, get the corresponding rank array * column If there are: Score = {4,2,5,4} * then output: Rank = {2,3,1,2}/Imp
ORT java.util.ArrayList;
Import java.util.Collections;
Import java.util.List;
public class Scorerank {//output array public static void show (int[] s) {for (int x:s) System.out.print (x);
System.out.println ();
//Get rank public static int[] Scorerank (int[] score) {int[] temp = new Int[score.length];
List lis = new ArrayList ();
for (int x:score)//add element (not repeat) if (!lis.contains (x)) Lis.add (x); Collections.sort (LIS); From small to large sort collections.reverse (LIS);
From large to small sort for (int i=0;i<score.length;i++)//subscript starting from 0 temp[i] = lis.indexof (score[i)) +1;
So: normal rank = get subscript + 1 return temp; public static void Main (string[] args) {int[] score = {4,2,5,4}; Rank {2,3,1,2} int[] rank = Scorerank (score);
Get the Rank System.out.print ("Original score:"); show (score);
System.out.print ("corresponding rank:"); show (rank); }
}
The results of the operation are as follows:
Original Score: 4254
Corresponding rank: 2312
I hope this article will help you with your Java programming.