|OCPJP 6|
matej spac wrote:Hello,
I have a problem with reading 2D array in spiral way. It must be read from bottom left corner - to bottom right corner - to top right corner etc like spiral. I try different approaches but still get in some step ArrayIndexOutOfBoundsException. Please help me complete "output" method.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
matej spac wrote:Hello,
I have a problem with reading 2D array in spiral way. It must be read from bottom left corner - to bottom right corner - to top right corner etc like spiral. I try different approaches but still get in some step ArrayIndexOutOfBoundsException. Please help me complete "output" method.
Well first, I don't see a program; I see a set of definitions and an output statement - admittedly with a loop, but that's not a program in any way I understand the word.
|OCPJP 6|
matej spac wrote:However, I follow your steps and it turns out that you are genius - I found solution in 15 minutes
![]()
Thanks.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
|OCPJP 6|
matej spac wrote:This solution works for any type of matrix, however, one senior programmer told me "it is not ideal and you use too many variables" .
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
What’s a 2D array? They might have them in some languages, but they don’t in Java. There are arrays of arrays in Java™, which are better than 2D arrays anyway.
SCJP
Visit my download page
Winston Gutkowski wrote:1. Don't mix the problem (making a spiral) with its representation (how it looks, or how you print out the results). If it were me, I think I'd be looking at a method that just returns me the coordinates of each point in the spiral (possibly even all of them together as an array). You could then use them to display the spiral any way you like.
Martin Vajsar wrote:Another possibility along these lines would be creating and returning an iterator that would traverse the 2D array in the required way.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Consider Paul's rocket mass heater. |