Java Matrix using Arrays -


i'm struggling find answer problem below. user inputs rows , columns. example below given 4 x 4 matrix.

1 8 9 16

2 7 10 15

3 6 11 14

4 5 12 13

i cannot find how relate numbers when printing array. obvious relation how goes downwards , upwards. perspective looks hard. i'm beginner.

not quite sure if there point post code, it's basic lines:

public static void main(string[] args) {     scanner scanner = new scanner(system.in);     system.out.println("please enter array rows: ");     int rows = scanner.nextint();      system.out.println("please enter array columns: ");     int columns = scanner.nextint();      int[][] array = new int[rows][columns];      int counter = 0;     (int j = 0; j < columns; j++){         (int = 0; < rows; i++) {             counter++;             array[i][j]=...(stuck @ beginning);         } 

probably i'd need use several loops , not above-mentioned or totally wrong ... thank in advance!

i think should it.

    int counter = 0;     boolean top_to_bottom=true;     (int j = 0; j < columns; j++){         (int = 0; < rows; i++) {             counter++;             if(top_to_bottom)              array[i][j]=counter;             else              array[rows-1-i][j]=counter;         }         if(top_to_bottom)          top_to_bottom=false;         else top_to_bottom=true;     } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -