我正在使用BlueJ。这是给我错误的代码。
public void printBackwards() {
int count = 5;
for (count = 5; count < holiday.length; count--) // Error: int cannot be dereferenced
{
System.out.println(holiday[count]);
count++;
}
这是我正在使用的全球阵列。
String [] holiday = new String [] {"St Paddy's Day", "Spring Break", "Christmas Break", "Easter", "Independence Day"};
任何人都知道导致错误的原因是什么?非常感谢你。
答案 0 :(得分:0)
试试这个有效:
class printBack {
public static void main(String[] args) {
int count;
String [] holiday = new String [] {"St Paddy's Day", "Spring Break", "Christmas Break", "Easter", "Independence Day"};
for (count = 0; count < holiday.length; count++)
{
System.out.println(holiday[holiday.length-count-1]); // Error: int cannot be dereferenced
}
}
}
输出:
Independence Day
Easter
Christmas Break
Spring Break
St Paddy's Day