Log in

View Full Version : Descending order


spiky22
Mar 5, 2015, 07:34 PM
I can only get correct nswer for two digit but when I mix 3 digit with two digit I cannot get correct output.
For output I need to display in descending order. Plese an anybody healp? In java


my code is:String acc = JOptionPane.showInputDialog("Enter a string:");
String[] s = acc.split(",");
ArrayList<String> arraylist = new ArrayList<String>();
for (int i = 0; i < s.length; i++) {
arraylist.add(s[i]);

}System.out.println(arraylist);


Collections.sort(arraylist, Collections.reverseOrder());
System.out.println("ArrayList in descending order:");
for(String str: arraylist){
System.out.println(str);}

CravenMorhead
Mar 6, 2015, 08:51 AM
If these are numbers why don't you convert them to Integers or Floats? Then the sort functions should have an easier time with it.

What does the output look like when you put in 3 digit numbers?