我的数组看起来像这样
String[] dayNames = new String[DAYS_IN_WEEK];
dayNames[0] = "Sunday";
dayNames[1] = "Monday";
dayNames[2] = "Tuesday";
dayNames[3] = "Wednesday";
dayNames[4] = "Thursday";
dayNames[5] = "Friday";
dayNames[6] = "Saturday";
我需要使用 findDay 方法打印数组的索引。
所以如果选择了“星期六”,我需要返回 6 个。
谢谢你的时间=D Ps 请没有答案?只是建议=)
更新* *
我的数组不会编译。这正是我所拥有的:
private static final int DAYS_IN_WEEK = 7;
String[] dayNames;
dayNames = new String[DAYS_IN_WEEK]
// Declare an array of Strings named dayNames
dayNames[0] = "Sunday";
dayNames[1] = "Monday";
dayNames[2] = "Tuesday";
dayNames[3] = "Wednesday";
dayNames[4] = "Thursday";
dayNames[5] = "Friday";
dayNames[6] = "Saturday";
我得到多个错误,开始于:
Weekdays.java:12: error: <identifier> expected
dayNames = new String[DAYS_IN_WEEK]
我不明白为什么。我从http://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html从字面上复制了 EXACT 格式