943,772 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1462
  • Java RSS
Feb 21st, 2009
0

How do i sort in descending?

Expand Post »
Java Syntax (Toggle Plain Text)
  1. package Sorting;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class Sorting2 {
  6. public static int s[] = new int[100];
  7.  
  8. public static void main(String[] args) {
  9.  
  10.  
  11. String ask = "";
  12. for (int i = 0; i< 5;i++){
  13. ask = JOptionPane.showInputDialog("Enter: ");
  14. s[i] = Integer.parseInt(ask);
  15.  
  16. System.out.println(s[i]);
  17.  
  18. }
  19.  
  20.  
  21. for (int x = s.length-1; x>= 0; x--) {
  22.  
  23. System.out.println(x);
  24. }
  25. }
  26. }

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
Reputation Points: 5
Solved Threads: 0
Light Poster
l_03 is offline Offline
37 posts
since Oct 2008
Feb 21st, 2009
0

Re: How do i sort in descending?

system.out.println(x); should be system.out.println(s[x]);
Featured Poster
Reputation Points: 1910
Solved Threads: 951
Posting Expert
JamesCherrill is offline Offline
5,768 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: add Image to Jwindow in BorderLayout.CENTER
Next Thread in Java Forum Timeline: Auto starting applications





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC