Reorganizing a 2d array in Java -



Reorganizing a 2d array in Java -

the comment in code i'm trying do, alter array "12345, 12345, 12345 111,222,333,444,555"

public void reorganize() { for(int y = 0; y < repeat; y++)//this loop reorganizes arrays. each array organized number location rather how inputted. ex: 12345, 12345, 12345 111,222,333,444,555 { for(int r = 0; y==4; r++) { newnumbers[r][y] = numbers[y][r]; } }

i've been trying prepare , i've rewritten couple times never ends working right. first time posting on , hope guys can help me (:

thank you

i suggest start passing in numbers array , returning newnumbers array. basically, logic should rotate dimensions of input numbers array build newnumbers, re-create logic right (once prepare loop test conditions).

public static int[][] reorganize(int[][] numbers) { int[][] newnumbers = new int[numbers[0].length][numbers.length]; (int y = 0; y < numbers.length; y++) { (int r = 0; r < numbers[y].length; r++) { newnumbers[r][y] = numbers[y][r]; } } homecoming newnumbers; }

then should able test like

public static void main(string[] args) { int[][] numbers = { { 1, 2, 3, 4, 5 }, { 1, 2, 3, 4, 5 }, { 1, 2, 3, 4, 5 } }; int[][] newnumbers = reorganize(numbers); system.out.println(arrays.deeptostring(newnumbers)); }

output (as requested)

[[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]]

java arrays multidimensional-array

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -