Trying Write Code Javascript Calendar Given Number Days Month Day Month Starts Start Day G Q24315830

Trying to write a code in javascript for a calendar given thenumber of days in a month and the day on which the month starts.The start day is given by the number 0-6, 0 denoting Sunday, 1denoting Monday, and so on. I’m attempting to modify this code:

public class Lab3p5 {
   public static void main(String [] args) {
       System.out.printf(” %4s %4s %4s %4s%4s %4s %4s”,”Sun”,”Mon”,”Tue”,”Wed”,”Thr”,”Fri”,”Sat”+”n”);
      System.out.println(“+——+——+——+——+——+——+——+”);
       printCalender(31, 6);
   }
   public static void printCalender(int days, int sunday){
       for(int i = 1; i <= 8 – sunday;i++){
          System.out.print(“| “);
       }
       for(int i = 1; i < sunday;i++){
          System.out.print(“| ” + i + ” “);
       }
       for(int i = sunday; i <= days;i++){
           if((i – sunday)% 7 == 0){
              System.out.println(“|”);
           }
           if(i >= 10)System.out.print(“| ” + i + ” “);
           elseSystem.out.print(“| ” + i + ” “);
          
       }
       System.out.println(“|”);
   }
}

…which similarly prints a calendar given the first Sunday ofthe month, but am strugglng to get any of my code to line up as acalendar when there are less than three weeks (i.e. if I’m doing a9 day month starting on 2 – Tuesday, it should look like:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

|____|____|__1__|__2__|__3__|__4__|__5__|

|_6__|__7_|__8__|__9__|_____|_____|_____|

“We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help”

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published.