Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: helo

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Thanked 0 Times in 0 Posts

    Default helo

    Hi Guys, how are you all. I seem to be having a problem getting my program to highlight the date which is typed as the third command line argument. There are three command line arguments; 1st one is the starting date, second is the month, and the third is the date to highlight.

    Here is the code:

    // Program to print a calendar for a given month.
    // First argument is the number of the start day, 1 to 7
    // Second argument is the last date in the month e.g. 28.
    public class CalendarHighlight
      public static void main(String [] args)
        printMonth(Integer.parseInt(args[0]), Integer.parseInt(args[1]));
      } // main
      // Print the calendar for the month.
      private static void printMonth(int monthStartDay, 
                                     int lastDateInMonth)
        // Keep track of which day 1 to 7 is the next day to be printed
        // out.
        int nextDayColumnToUse = monthStartDay;
        // Keep track of next date to be printed out.
        int nextDateToPrint = 1;
        // Print top line of calendar.
        // Print headings i.e. su, mo, tu etc.
        // Print out minimum 6 rows to ensure consistent format.
        int noOfRows = 0;
        while (nextDateToPrint <= lastDateInMonth || noOfRows < 6)
          // Print one row.
          System.out.print(" | ");
          for (int dayColumnNo = 1; dayColumnNo <= 7; dayColumnNo++)
    	// Print a space separator between day columns.
            if (dayColumnNo > 1)
    	  System.out.print("    ");
    	// We either print spaces or date.
    	if (dayColumnNo != nextDayColumnToUse
    	    || nextDateToPrint > lastDateInMonth)
    	} // else
          } // for
          // Print separator and end the row.
          System.out.println(" | ");
          // The next row.
          nextDayColumnToUse = 1;
        } // while
        // Print bottom line of calendar.
      } // printMonth
      // Print line of hyphens as wide as table starting with
      // spaces and ending with spaces so it looks right.
      private static void printMonthLineOfHyphens()
        System.out.print("  ");
        for (int dayColumnNo = 1; dayColumnNo <= 7; dayColumnNo++)
          if (dayColumnNo > 1)
        } // for
        System.out.println("    ");
      } // printMonthLineOfHyphens
      // Print headings of days in the week.
      private static void printDayNames()
        System.out.print(" | ");
        for (int dayColumnNo = 1; dayColumnNo <= 7; dayColumnNo++)
          if (dayColumnNo > 1)
            System.out.print("    ");
        } // for
        System.out.println(" | ");
      } // printDayNames
      // Print Day names as two characters.
      private static void printDayName(int dayNo)
        // Days in the week are numbered 1 - 7 from sunday so:
        switch (dayNo)
          case 1: System.out.print("Su"); break;
          case 2: System.out.print("Mo"); break;
          case 3: System.out.print("Tu"); break;
          case 4: System.out.print("We"); break;
          case 5: System.out.print("Th"); break;
          case 6: System.out.print("Fr"); break;
          case 7: System.out.print("Sa"); break;
        } // switch
      } // printDayName
      // Print spaces as wide as date between the dates.
      private static void printDateSpace()
        System.out.print("  ");
      } // printDateSpace
      // Print hyphens as wide as the date.
      private static void printDateHyphens()
      } // printDateHyphens
      // Print date using two characters, with leading zero if required.
      private static void printDate(int date)
        System.out.printf("%02d", date);
      } // printDate
    } // class CalendarHighlight

    Any suggestions guys?

    Kind regards

    Last edited by Shyamz1; November 23rd, 2010 at 11:58. Reason: Wrong code

  2. #2
    Registered Users javapenguin's Avatar
    Join Date
    May 2010
    North Central Illinois
    My Mood
    Thanked 112 Times in 110 Posts

    Default Re: helo

    What do you mean by highlight?
    Please mark solved threads as "Solved" by going to threads and clicking "Mark Solved"
    Using code tags

    How To ask questions the smart way
    Java Tutorials
    Java API
    Save Our Snips
    Hit THANKS to thank a person. Hit REP+ to increase reputation (or decrease it). Cannot give to same person for a while.
    Shooting Park Road Baptist Church Site

Similar Threads

  1. helo
    By FaintSmile in forum Member Introductions
    Replies: 1
    Last Post: July 14th, 2010, 02:33