-1
我有這樣的代碼:如何使用Array和if else語句?
String[] sweetFlevors = { "Caramel", "Cinnamon", "Wetermelon", "Backed Beans" };
String[] savoryFlavors = { "Sea Salt", "Potato Chip", "Carrot", "Barbque" };
int[] numberRows = { 1, 2, 3, 4 };
int[] numberCol = { 1, 2 };
for (int col = 0; col < numberCol.length; col++) {
System.out.println(" " + numberCol[0] + " " + numberCol[1]);
for (String sweet: sweetFlevors) {
for (String savory: savoryFlavors) {
for (int row = 0; row < numberRows.length; row++) {
System.out.print(numberRows[row] + ". ");
System.out.println(sweet + " and " + savory);
}
}
}
}
和我的輸出是這樣的:
1 2
1. Caramel and Sea Salt
2. Caramel and Sea Salt
3. Caramel and Sea Salt
2. Wetermelon and Carrot
3. Backed Beans and Barbque
4. Backed Beans and Barbque
1 2 // How to delete this line?
1. Caramel and Sea Salt
2. Caramel and Sea Salt
我不知道我怎麼可以刪除第二行列?爲什麼我得到它?
感謝你幫我:)
你問的是真的不清楚。你應該解釋你想做什麼,你得到什麼,並請以可讀的方式格式化你的代碼。 – davidxxx
我必須練習ARRAY,因此我會做各種各樣的代碼練習。 – ein