Find X,Y Coordinates Inside 2D array

Run Settings
LanguageJava
Language Version
Run Command
class Main { public static void main(String[] args) { int x,y;x=0;y=1; //setup variables for coordinates (in one line) System.out.print("x:"+locateBot()[x]+" y:"+locateBot()[y]); //print x,y! } /* * This method will generate the map based on * predetermined values. It can also use a scanner * to generate a map from a txt file */ public static int[][] map(){ int [][] mapData = { {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,1,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0} }; return mapData; //make available to other methods } /* * This method will print the map if needed */ public static void printMap(int[][]map){ for(int row=0; row<map.length;row++){ for (int col=0; col<map[0].length;col++){ System.out.print(map[row][col]); } System.out.println(); } } /* * This method will return the x and y coordinates * in an array with the first value being x and the * second value being y coordinate */ public static int[] locateBot(){ int botLocation[] = new int[2]; //create bot location x,y coordinate array int scannedData[][] = map(); //bring in the map for(int row=0; row<scannedData.length;row++){ for (int col=0; col<scannedData[0].length;col++){ if(scannedData[row][col]==1){ //FIND LOCATION OF THE ROBOT!!!!! botLocation[0]=row; //set first value as "x" position botLocation[1]=col; //set next value as "y" position } } } return botLocation; //return the x,y coordinates as position 0 and 1 of the array } }
Editor Settings
Theme
Key bindings
Full width
Lines