Java Array Methods Question?
Nick
Could you set up constants and fill it that way? If you're determined to prefill your 2D array with predefined values, that's what I'd look at. Perhaps a long constant as a string, comma delimited and then to a conversion from text to integer?
brilliant_moves
Hi, Jimmy. I've provided a test program to ensure the method works as intended. import java.util.Arrays; public class ArrayMethodsQuestion { ... public static int[][] fillArray(int[][] theArray, int x) { ... ... for (int i=0; i<theArray.length; i++) { ... ... ... for (int j=0; j<theArray[i].length; j++) { ... ... ... ... theArray[i][j] = x; ... ... ... } ... ... } ... ... return theArray; ... } ... public static void main (String[] args) { ... ... int[][] anArray = new int[5][7]; ... ... anArray = fillArray (anArray, 10); ... ... for (int i=0; i<anArray.length; i++) { ... ... ... System.out.println (Arrays.toString (anArray[i])); ... ... } ... } } //Note: I've used "... " to show indentation (which Y!A removes). Replace dots with a tab or spaces in your code.
Impaled
Read your textbook.