Advertisement

对一组数进行排序并输出其索引

阅读量:
复制代码
 package com.com.henu;

    
  
    
 import java.util.*;
    
 /*
    
 给一组随机数数【1-100】,每个数带有其序号,将这组数进行排序后,也输出他与之对应的序号
    
  */
    
 public class Demo01 {
    
     public static void main(String[] args) {
    
     Map<Integer,Integer> hmap = new HashMap<>();
    
     int count = 1;
    
     //将随机数存到map中去,以序号作为key值,随机数作为value1值
    
     for (int i = 0; i < 10; i++) {
    
         int x = (int) (1+Math.random()*100);
    
         hmap.put(count++,x);
    
     }
    
     System.out.println("The data that goes in : " + hmap);
    
     List<Integer> list = new ArrayList<>();
    

全部评论 (0)

还没有任何评论哟~