Jacob
Dan D'amico wrote:this outputs are what i need to accomplish.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Dan D'amico wrote:this outputs are what i need to accomplish.
OK, but the "what" is actually more generic than that, and shouldn't matter whether your array contains RGB values, letters, or multi-coloured bouncing balls.
What you need to do is think:
1. (as Carey already pointed out) in your specific case, a 4 x 3 array will be a 3 x 4 array when it's "rotated". But what if it was a 6 x 3 array? or 137 x 43?
2. Where does each cell from the original array go into a "rotated" one? For example, where does (0,0) end up? And what about (0,1)? Or (1,0)? Go through a few of these and see if a pattern emerges - especially one that relates to the width and height of the original, because then you'll be able to implement it for ANY 2D array.
Just as a kick-start, (0,0) will end up at (0,2) in your "rotated" array, but the important question is why ... and how does it relate to the original width and height?
I'd suggest using copious amounts of paper and a pencil, and drawing lots of diagrams - and don't write one line of Java code until you really understand what it's going to do.
HIH
Winston
Dan D'amico wrote:but then i get an Exception error. ArrayIndexOutOfBounds
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Dan D'amico wrote:but then i get an Exception error. ArrayIndexOutOfBounds
Because Java array indexes start from 0.
Think about it: if they didn't, you couldn't possibly have a (0, 0) object could you?
So: given that you now know that, what is the largest index you can have for a [4][3] array?
Winston
Dan D'amico wrote:12.2
but it still not worked. give me the exception error.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Dan D'amico wrote:12.2
but it still not worked. give me the exception error.
Because your answer is wrong. One part of it is right, but the other isn't (where do you get '12' from?)
Winston
Dan D'amico wrote:i declare the 2 dim array and when initilaize it to 3,4
it can contains no more than 12 elements
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Dan D'amico wrote:i declare the 2 dim array and when initilaize it to 3,4
it can contains no more than 12 elements
So, even if your assumption was correct (which it isn't), the largest index value would be 11, wouldn't it?
But you have a 2D array, so you have two indexes: one for the "row", one for the "column".
Think about it a bit more, and see if you can't work it out for yourself (you'll be much prouder if you do). And if you really can't fathom it, come back.
Winston
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |