1. Member
Join Date
Nov 2012
Posts
4
Rep Power
0

## Incrementing variables

I am having trouble trying to increment the startYear variable by 1 for 10 consecutive years (e.g. 2012, 2013, 2014, 2015....). This is my first programming course, as well as my first attempts at using iteration. I have attempted a few things such as startYear++ in the loop and right after to see the results, but it did not affect anything. Any information to get me in the right direction would be appreciated.

Java Code:
```public void printHalloweens(int startYear)
{
Date d1 = new Date(10, 31, startYear);

for (int i = 0; i < 10; i++)
{
System.out.println(d1.getDayOfWeek());
}
}```

2. Moderator
Join Date
Apr 2009
Posts
10,484
Rep Power
16

## Re: Incrementing variables

You need a new Date for each year.
Unless there is a setYear() method on that Date class.
Not sure what Date class it is, though.

3. Member
Join Date
Nov 2012
Posts
4
Rep Power
0

## Re: Incrementing variables

These were the only mutators I was given for the assignment.

Java Code:
```Date d = new Date(1,1,2012) ;  // d is January 1, 2012 (a leap year)

d.next() ;                     // d is January 2, 2012
d.previous() ;                 // d is January 1, 2012
d.add(31) ;                 	 // d is February 1, 2012
d.subtract(32) ;               // d is December 31, 2011
d.next() ;         			 // d is January 1, 2012

d = new Date(3,1,2012) ;  	 // d is March 1, 2012
d.previous() ;                 // d is now February 29, 2012```

4. Member
Join Date
Nov 2012
Posts
4
Rep Power
0

## Re: Incrementing variables

My objective is to get the day of the week Halloween falls on for the next 10 years. I did this to the loop, but not sure if its really an accurate portrayal.

Java Code:
```public void printHalloweens(int startYear)
{
Date d1 = new Date(10, 31, startYear);

for (int i = 0; i < 10; i++)
{
System.out.println(d1.getDayOfWeek());
}

}```

5. Moderator
Join Date
Apr 2009
Posts
10,484
Rep Power
16

## Re: Incrementing variables

Then create a new Date inside the loop for each of the 10 years and print that.

6. Member
Join Date
Nov 2012
Posts
4
Rep Power
0

## Re: Incrementing variables

Alright, thank you for the help.
:)