Results 1 to 2 of 2
  1. #1
    Jude is offline Member
    Join Date
    Nov 2007
    Rep Power

    Red face Problems with Calendar exercise

    I have been set a task to display a calendar for any given month and year.
    I made a start by using a text book but I cant seem to get what i need from it.

    So far I have used GregorianCalendar and I can display a calendar. I first thought it was todays date but it isn't it seems to be a random month and year.
    Although I am having alot of problems the biggest problem is that I need to be able to input a given month and year, and then display that.
    I have read that I can use scanner or get (I think?) :confused:

    I need alot of help and explaining for this as I am absolutly new to java. Any help or advice would be appreciated. Thanks. :)

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    Java Code:
    import java.text.*;
    import java.util.*;
    public class Test {
        public static void main(String[] args) {
            // Calendar practice.
            DateFormat df = new SimpleDateFormat("dd MMM yyyy");
            Date now = Calendar.getInstance().getTime();
            System.out.println("now = " + now);
            System.out.println("now = " + df.format(now));
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.MONTH, Calendar.MAY);
            System.out.println("set to May = " + df.format(calendar.getTime()));
            calendar.set(1997, 8, 24);
            System.out.println("set to 1997 = " + df.format(calendar.getTime()));
            calendar.roll(Calendar.DAY_OF_MONTH, 7);
            System.out.println("7 days ahead = " + df.format(calendar.getTime()));
            // Try some input.
            Scanner scanner = new Scanner(;
            System.out.println("enter a four digit year");
            int year = scanner.nextInt();
            System.out.println("enter a Month");
            int month = scanner.nextInt();
            System.out.println("Enter a day of the month");
            int day = scanner.nextInt();
            System.out.printf("year = %d  month = %d  day = %d%n",
                               year, month, day);
            calendar.set(year, month, day);
            System.out.println("you entered " + df.format(calendar.getTime()));

Similar Threads

  1. exercise of recursive method
    By amexudo in forum New To Java
    Replies: 2
    Last Post: 03-09-2008, 05:55 PM
  2. Prob with an exercise
    By jhetfield18 in forum New To Java
    Replies: 4
    Last Post: 02-15-2008, 06:11 PM
  3. I/O exercise
    By Feldom in forum New To Java
    Replies: 1
    Last Post: 10-28-2007, 04:48 PM
  4. help with exercise
    By e_as're in forum New To Java
    Replies: 3
    Last Post: 09-25-2007, 10:14 AM
  5. help with an exercise calcuting tax
    By e_as're in forum New To Java
    Replies: 7
    Last Post: 08-01-2007, 03:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts