Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Assignment#2 Question 6
- import java.util.Scanner;
- public class Ass2_6{
- public static void main(String[]args){
- Scanner input = new Scanner(System.in);
- // Variables
- int start;
- int year;
- int day;
- int blank = 0;
- int count = 0;
- int month_count;
- int month_end = 0;
- String month = "";
- // User Input
- System.out.print("What year is it? ");
- year = input.nextInt();
- System.out.print("Year begins on what day of the week?(0-6) ");
- start = input.nextInt();
- // Entire Calendar runs on loop; one loop = one month
- for(month_count = 1; month_count <= 12; month_count++){
- // Pre-print switch
- switch(month_count){
- case 1: month = "January"; month_end = 31; break;
- case 2: month = "Febuary"; month_end = 28; start = count; break;
- case 3: month = "March"; month_end = 31; start = count; break;
- case 4: month = "April"; month_end = 30; start = count; break;
- case 5: month = "May"; month_end = 31; start = count; break;
- case 6: month = "June"; month_end = 30; start = count; break;
- case 7: month = "July"; month_end = 31; start = count; break;
- case 8: month = "August"; month_end = 31; start = count; break;
- case 9: month = "September"; month_end = 30; start = count; break;
- case 10: month = "October"; month_end = 31; start = count; break;
- case 11: month = "November"; month_end = 30; start = count; break;
- case 12: month = "December"; month_end = 31; start = count; break;
- default: System.exit(0);
- }
- // Print Calendar
- System.out.println("\n" + " " + month + " " + year + "\n");
- System.out.print("Sun " + "Mon " + "Tue " + "Wed " + "Thu " + "Fri " + "Sat " + "\n");
- // Print Blanks
- for(blank = 0; blank < start; blank++){
- System.out.print(" ");}
- // First Week
- for(day = 1; day <= ( 7 - blank); day++){
- System.out.print(" " + day + " ");
- if(day == (7 - blank))
- System.out.println(""); count = 0;}
- // Rest of Calendar Loop
- for(day = day; day <= month_end; day++){
- count += 1;
- if(day < 10){
- System.out.print(" " + day + " ");}
- if(day >= 10){
- System.out.print(" " + day + " ");}
- if(count == 7){
- System.out.println("");
- count = 0;
- }}
- System.out.print("\n" + "\n");
- }
- }
- }
Add Comment
Please, Sign In to add comment