Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Help with Decending order for float. I am trying to sort out decimal #'s in Decending order. When i go run the program it dosen't sort it out. Can anyone help me out?

import java.util.Arrays;

public class SelectionSort {

	public static void main(String[] args) {
	
	// initialize a new float array
	float[] a = new float[]{1.12f,7.32f,3.21f,1.07f,9.2f,1.7f,10.12f};
	
	
	java.util.Collections.reverseOrder();
	
	// print the sorted array of float
	System.out.println(Arrays.toString(a));

	}
}

What I have tried:

I tried Array.sort. now im trying java.util.
Posted
Updated 3-Oct-18 20:50pm
v3
Comments
Patrice T 3-Oct-18 16:55pm    
Try to learn properly the language.
You are missing the most basic things,you have to tell what you want to sort. This Java 101.
Member 13987805 3-Oct-18 17:20pm    
I am still learning it, im very new to it, thats why i need help.
Patrice T 3-Oct-18 17:45pm    
Advice: follow some tutorials to get familiar with basics.
Once it is done, start personal projects.
Member 13987805 3-Oct-18 17:49pm    
Someone Help me out with this. Simple as that. Just help on Decending
Eric Lynch 3-Oct-18 21:56pm    
To use any of the Java methods, you need to have a basic understanding of how they work. Since there are already a lot of good explanations elsewhere, it doesn't make much sense to repeat those explanations here. For example, a quick Google provides the following link which has a number of different examples of reverse sorting...

See: https://www.geeksforgeeks.org/collections-reverseorder-java-examples/

I recommend you read the explanations, copy the code that's closest to what you want, run it in the debugger (so you can see it work), and then make the small number of changes necessary to solve your exact problem.

1 solution

Perhaps if you passed the array you wanted to sort to the function, it would help:
java.util.Collections.reverseOrder();
It's not about to guess what you wanted to sort!
Collections.reverseOrder() in Java with Examples - GeeksforGeeks[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900