Results 1 to 2 of 2

Thread: [RESOLVED]My program cannot work for float array

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2006
    Posts
    21

    Resolved [RESOLVED]My program cannot work for float array

    My program works alright for integer array, but not float array. How can I change the program so that I can get the original position of each element in the float array after sorting? Let's say my float array is {5.0f,10.0f,1.0f,15.0f}.
    Here's my code:
    Code:
    import java.util.*;
    
    public class SortArrays
    {
    	public static void main(String args[])
    	{
    		Integer[] score = {5, 10, 0, 1, 15};
    
    		ArrayList Values = new ArrayList();
    		HashMap OriginalPos = new HashMap();
    
    		for(int i=score.length-1;i>=0;i--)
    		{
    			OriginalPos.put(new Integer(score[i]), new Integer(i));
    			Values.add(new Integer(score[i]));
    		}
    	
    		Collections.sort(Values);
    
    		for(int i=Values.size()-1;i>=0;i--)
    		{
    			int val = ((Integer)(Values.get(i))).intValue();
    			System.out.print("" + val + "    ");
    			System.out.println(OriginalPos.get(new Integer(val)));
    		}
    	}
    }
    Last edited by huiling25; Jan 30th, 2007 at 01:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width