Here's my question for you: I see a lot of code, and you seem to think there's a logic error in it. But what makes you think that? Have a look at our FAQ entry named TellTheDetails (<-- click on that link) if you don't see why I asked that question.
I also think you are going the wrong way about writing the application. I think you should write a utility class with methods which swap two elements in an array, reverse an array, etc. You can do the reversing with the entire array, because that isn't a 2D array. It is an array of arrays. So you treat the outer array as one array and simply write a method to reverse it. I shall give you a start: you have to declare the method as generic with the <T>, so you can pass an array of any reference type:-Once you have those two methods working, you can keep them for ever.
posted 3 years ago
Unfortunately, my prof hasn't done utilities with us at all. I created a tester class that worked, but I can't figure out how to put it into my other main program:
posted 3 years ago
Ayugm Acharya wrote:Unfortunately, my prof hasn't done utilities with us at all.
Maybe not, but you have asked on a reputable website and been given the suggestion. You have also been given the suggestion that swapping two elements and reversing an array merit methods of their own.
I created a tester class that worked, . . .
Clever programming, creating a stack and using that for reversing, but what did the program do? It has not reversed the array. Reversing the array would put row₀ last and rowₙ first. You have gone one further and reversed the included arrays as well. By the way: to print your matrix, use this (not in the loop):-
Dividing the task into smaller stages will make the problem easier to solve. A standard programming technique which everybody should know. If you reverse the included arrays, you will need to overload those methods to take ints.Once you have worked out the logic for one method, the other method will use the same logic.