I met a problem. There is a 2d array include 12 cities' trade volume in each month. The cities are listed in a string array. I'm trying to make a table to list the city trade records each month.I tried to use a nested 3 -times for loop but the cities name always in the circulation for several times,it only need once to appear in the first colunm of each city. Can someone tells me where is my problem? I'm out of mind.
I can't add pictures but I can tell you the program keep generate city names in each first column. I think I should not put the city array in the for loop. But how can I add the city name to each row only once?
int[][] sold =
{
{ 190, 180, 435, 110, 223, 130, 123, 103, 135, 300, 392, 324 },
{ 520, 737, 264, 822, 562, 645, 205, 447, 126, 214, 2784 2138 },
{ 1103, 2203, 2376, 3038, 1721, 2463, 3541, 1183, 1213, 3310, 1416, 1523 },
{ 2110, 2630, 234, 108, 1439, 202, 2163, 538, 2414, 1155, 167, 2121 },
{ 2031, 274, 2236, 1823, 152, 107, 1912, 265, 123, 1130, 146, 1152 },
{ 2233, 1814, 2316, 2334, 1167, 1231, 2048, 2011, 1486, 1109, 1441, 1176 },
{ 1361, 2119, 1313, 1911, 1873, 2011, 2783, 1046, 1513, 1732, 1109, 1416 },
{ 2011, 1043, 1221, 131, 1231, 169, 2146, 1001, 123, 161, 619, 175 },
{ 1010, 2345, 106, 222, 175, 143, 2018, 1517, 163, 141, 208, 189 }
};
String[] cities= {
"Miami",
"Perth",
"Sydney",
"Tokyo",
"Mosco",
"Winnipeg",
"London",
"Beijing",
"Guelph"
};
Thanks a lot
And I write code like this
for(int city = 0;city<cities.length;city++) {
System.out.printf("%s\n", cities[city]);
for(int i = 0; i<sold.length;i++) {
for(int j =0;j<sold[i].length;j++) {
System.out.printf("%15d",sold[i][j]);
}
}System.out.println();
}