Returning a 2D Array

Run Settings
LanguageJava
Language Version
Run Command
class Main { public static void main(String[] args) { printNewArray(); //run the printNewArray method } /* * This method will generate a new 10x10 array with the letter x and * return the 2D array for use in another method. * */ public static String [][] generate2DArray(){ String [][] my2DArray = new String[10][10]; for(int row=0;row<my2DArray.length;row++){ for(int col=0;col<my2DArray[0].length;col++){ my2DArray[row][col]="x"; } } return my2DArray; } /* * This method will generate a new 10x10 array using what was returned from * generate2DArray and output it to the screen. * */ public static void printNewArray(){ String[][]new2DArray=generate2DArray(); for(int row=0;row<new2DArray.length;row++){ for(int col=0;col<new2DArray[0].length;col++){ System.out.print(new2DArray[row][col]); } System.out.println(); } } }
Editor Settings
Theme
Key bindings
Full width
Lines