A two-dimensional array can not initialize the number of columns (second dimension).
The following example shows two different ways to store a two-dimensional array and output:
1. This is our easy-to-understand two-dimensional array storage method:
string[][] data = new string[][] {{"Youth", "High", "No", "fair", "No"},{"youth", "High", "No", "excellent", "No"},{" Middle_aged "," High "," No "," fair "," Yes "},};for (string[] s:data) {for (String str:s) System.out.print (str +" \ T "); s Ystem.out.println ();}
Output Result:
Youthhighnofairnoyouthhighnoexcellentnomiddle_agedhighnofairyes
2. This is the method of defining the second dimension as an array of strings, which is required for the output to be forced character conversions:
object[] array = new object[] {new string[] {"Age", "income", "Student", "credit_rating", "Buys_computer"},new string[] { "Youth", "High", "No", "fair", "No"},new string[] {"Youth", "High", "No", "excellent", "no"},; for (int i = 0, i < array.length; i++) {for (int j = 0; J < ((string[]) array[0]). length; j + +) System.out.print (<s Pan style= "color: #ff0000;" > ((string[]) array[i]) [j]</span> + "\ t"); System.out.println ();}
The output is the same as above.
Initialization and output of arrays