I gotta print all months of the year in their calendars given the year and the first day of the month.
I don't understand how to put this in a table.
Of course I got the headings ready...but that's as far as I got...
I just want to know how to put the days in their specific day of the week in calendar form with only the first day of the year...
It's been 2 hours since I started and I still got nothing
this is as far as I can go, but sth is still so wrong...
it's pretty messed up...
import java.util.Scanner;
public class calendar {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the year: ");
int year = scanner.nextInteger();
System.out.print("Enter 1st day of year ( 0 = Sunday, 6 = Satuday ): ");
int firstDay = scanner.nextInteger();
for ( int month = 1; month <= 12; month++ ){
System.out.println(" " + month + " " + year);
System.out.println("---------------------------------");
System.out.println("Sun Mon Tue Wed Thu Fri Sat");
}
String monthName = " ";
switch (month) {
case 1: monthName = "January";
days = 31;
break;
case 2: monthName = "February";
if(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
days = 29;
} else {
days = 28;
}
break;
case 3: monthName = "March";
days = 31;
break;
case 4: monthName = "April";
days = 30;
break;
case 5: monthName = "May";
days = 31;
break;
case 6: monthName = "June";
days = 30;
break;
case 7: monthName = "July";
days = 31;
break;
case 8: monthName = "August";
days = 31;
break;
case 9: monthName = "September";
days = 30;
break;
case 10: monthName = "October";
days = 31;
break;
case 11: monthName = "November";
days = 30;
break;
case 12: monthName = "December";
days = 31;
break;
default: JOptionPane.showMessageDialog(null,"Error: this month does not exist"); System.exit(0);
break;
}
}
}
thank you in advance...

New Topic/Question
Reply




MultiQuote





|