-7

I'm using BlueJ. This is the code that's giving me the error.

public void printBackwards() {
    int count = 5;

    for (count = 5; count < holiday.length; count--) // Error: int cannot be dereferenced
    {
        System.out.println(holiday[count]);
        count++;
    }

This is the global array I'm working with.

String [] holiday = new String [] {"St Paddy's Day", "Spring Break", "Christmas Break", "Easter", "Independence Day"}; 

Anyone know what is causing the error? Thank you very much.

G_Man
  • 33
  • 1
  • 7

1 Answers1

0

try this it works :

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
    }
}
}

OUTPUT :

Independence Day
Easter
Christmas Break
Spring Break
St Paddy's Day
adrCoder
  • 2,821
  • 1
  • 23
  • 40