| | |
How do i sort in descending?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2008
Posts: 37
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
package Sorting; import javax.swing.JOptionPane; public class Sorting2 { public static int s[] = new int[100]; public static void main(String[] args) { String ask = ""; for (int i = 0; i< 5;i++){ ask = JOptionPane.showInputDialog("Enter: "); s[i] = Integer.parseInt(ask); System.out.println(s[i]); } for (int x = s.length-1; x>= 0; x--) { System.out.println(x); } } }
This is my code ,i want to sort in descending the input that i made,,the problem is it does not output the descending order of the numbers i input. This is my sample input:
Enter: 2 6 8 5 7 9
Output: 9 8 7 6 5 2
But the output is:
Output: 100..............1,
because of the [100] i assigned in int [s], wil somebody help me? i really dont know how to fix it. I hope you can help me. Thank you in advance.
![]() |
Similar Threads
- descending (C++)
- sort array (C++)
- Sort in descending order.... (C++)
- How to sort?? (C++)
- how to read a csv file and sort the specific clolumn in descending order (C#)
- I can't sort out Insertion Sort! (C)
- Selection Sort on a string with char and int? (C++)
Other Threads in the Java Forum
- Previous Thread: add Image to Jwindow in BorderLayout.CENTER
- Next Thread: Auto starting applications
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui health html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





