• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Issue with two dimensional arrays

 
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the program bellow that grades students(based on a two dimensional array with the answers) and i need to make it display the students based on the grades/scores in ascending order . I did that in two ways (using a array and a two dimensional array) but i have a hunch it can be done much more simple then i did it (but still using array object and nothing else ) . Any input about how to solve the problem in a more easy way is appreciated !



My first solution creating an array with the grades for sorting :




My second solution using a two dimensional array :


 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I only see one-dimensional arrays here. That's because Java only supports one-dimensional arrays, but they can hold...arrays.

In other words, you have an array that holds a bunch of character arrays.
 
Tiberius Marius
Ranch Hand
Posts: 115
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well , in the book that i m learning Java from i have a whole chapter called Multidimensional Arrays.
 
Marshal
Posts: 80637
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In which case the book is wrong, or at least misleading.
Start by writing yourself a utility class for arrays. I'll give you a start. Private constructor because you never need any instances of it. All methods static.Always use the methods of that class; never put sorting logic in other methods. If the methods you have already work you can simply copy them into the utility class.
 
reply
    Bookmark Topic Watch Topic
  • New Topic