The Java implementation gives the method of getting the fractional array to the corresponding rank array _java

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.