| | |
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 add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying oracle page pearl print problem program programming project qt recursion scanner screen scrollbar server set size sms sort spamblocker sql string swing system thread threads time tree variablebinding windows xor





