A bit of advice needed here, I am trying to code Create a String Array containing any six first names. Use an enhanced for loop to print each name in the array Here is what I have:
public class names {
private static String[] arrayString;
private static String[] names;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String[][]firstnames={
{"John", "Mary", "Harry", "Ray", "Sean", "Matthew" },
};
for (int row=0;row<firstnames.length;row++){
for(int col=0; col<firstnames[row].length; col++){
System.out.print(firstnames[row][col]+ " ");
System.out.println();
}
}
}
}
I am being told that you have used fixed values for the conditions on the loops instead of the lengths of the array.
It is better to use the length of the array for maintenance etc
I have spent a long time trying to figure out where I have gone wrong, as far as I can see I have answered the question. Can someone point me in the right direction?