File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "need help" Watch "need help" New topic
Author

need help

rkelite Henil
Greenhorn

Joined: Sep 29, 2009
Posts: 2
ok this is my code
...I want to sort the arrays in descending order..How do I do that?
Please anyone can help me!!
thakn you so much



Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39773
    
  28
Welcome to JavaRanch

Please don't write all UPPERCASE, make sure to use the CODE button, and use a thread title with a real meaning.
Since you are new I have sorted some of those problems, and yo can see how much better the code looks.

Both those methods ought to be static, because they require no information from an object and don't supply information to an object. The increase size method looks all right, but I would suggest you take a second parameter: int increment. That way you can increase the size of the array by 2, 3, 4, or 183277652 members. A test for "if (increment > 0)" might help; it will prevent you creating a smaller array There are ready-made methods which allow you to copy an array, in part or whole. I won't tell you where, but will give a hint: this class.

Your sorting method appears to implement a bubble sort. I would suggest you implement a sort method and a reverse method and use both. Make both those methods static.
Your sort method appears to be using title, studio and year. What do those mean? They appear to have nothing to do with the array; get rid of them. Make sure your swap method works and takes the sort of array you have as an argument (String[] array) and swaps two elements. Then all you have to do is pass the array you are swapping, and the two index numbers, to your swap method and it will work.
I haven't inspected your for loops to see whether there is any risk of your going beyond the bounds of your arrays; I shall leave you to do that.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39773
    
  28
And have a look at this thread; see whether it is helpful to you.
rkelite Henil
Greenhorn

Joined: Sep 29, 2009
Posts: 2
oh im so sorry...i didnt know how to do that n see..my book tells me to use those codes and sort them in descending order so is there any way? using this code??
THakn you
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385

Use this from collection framework.

Arrays.sort(arrayToSort, Collections.reverseOrder());


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39773
    
  28
Siva Masilamani wrote:
Use this from collection framework.

Arrays.sort(arrayToSort, Collections.reverseOrder());
That is probably not what the assignment requires. It requires you to write a reverse method. I shall give you a startAnd the comments are there for a reason
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39773
    
  28
You will also need a sort method which sorts in ascending order.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need help