java - Getting indexes from two-dimensional array -


how can int = 400; int b = 100; 2-dimensional array 1000 x 1000 in java, example, mass[400][100] (row 400, column 100)? found element in array , need numbers of row/line , column. how can numbers? thanks.

if need find position in array based on value, have no other option brute-force loop through whole array, breaking out when find first match:

int[][] massivearray = new int[1000][1000];  final int valuetofind = 27; // assign value find @ position (400, 100) massivearray[400][100] = valuetofind;  int i_value = -1; int j_value = -1;  // find first occurrance of valuetofind looping through array outer: (int = 0; < massivearray.length; i++) {     (int j = 0; j < massivearray[0].length; j++) {         if (massivearray[i][j] == valuetofind) {             i_value = i;             j_value = j;             break outer;         }     } }  system.out.println(string.format("first position %d @ (%d, %d)",      valuetofind, i_value, j_value)); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -