Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

need help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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



 
Marshal
Posts: 69806
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 69806
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And have a look at this thread; see whether it is helpful to you.
 
rkelite Henil
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Use this from collection framework.

Arrays.sort(arrayToSort, Collections.reverseOrder());
 
Campbell Ritchie
Marshal
Posts: 69806
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Marshal
Posts: 69806
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will also need a sort method which sorts in ascending order.
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic