954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do i sort in descending?

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.

l_03
Light Poster
37 posts since Oct 2008
Reputation Points: 5
Solved Threads: 0
 

system.out.println(x); should be system.out.println(s[x]);

JamesCherrill
Posting Genius
Moderator
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You