Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

'.class expected' error; inside For loop

843810Nov 24 2007 — edited Dec 11 2007
I am making a program to list every day in a year that the user inputs as a command line argument. Here's the relevant code:
class DisplayDays {
	public static void main(String[] arguments) {
		int yearIn = 2008;					//default in case user doesn't enter a year
		if (arguments.length > 0)				//if user enters year, that's what we work with
			yearIn = Integer.parseInt(arguments[0]);
		For (int month = 1; month <= 12; month++) {
			int daysInMonth = countDays(month, yearIn);
			For (int dayOfMonth = 1; dayOfMonth <= daysInMonth; dayOfMonth++) {
				System.out.println(month + "/" + dayOfMonth + "/" + yearIn);
			}
		}
	}
//for each month, find the number of days in it
	static int countDays(int month, int year) {
		int count = -1;
		switch (month) {
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				count = 31;
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				count = 30;
				break;
			case 2:
				if (year % 4 == 0)
					count = 29;
				else
					count = 28;
				if ((year % 100 == 0) & (year % 400 != 0))
					count = 28;
		}
		return count;
	}
}
When I tried to compile, there was an error on line 6, '.class' expected. What am I doing wrong??
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 8 2008
Added on Nov 24 2007
4 comments
390 views