3 Replies - 4812 Views - Last Post: 20 October 2010 - 01:32 AM Rate Topic: -----

#1 Moustafa taha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 28-September 10

Display the first day of each month in a year

Posted 19 October 2010 - 06:53 PM

hello guys, this is my program
Write a program that prompts the user to enter the year and first day of the year, and displays the first day of each month in the year on the console. For example, if the user entered the year 2005, and 6 for Saturday, January 1, 2005, your program should display the following output:
January 1, 2005 is Saturday
...
...
...
...
December 1, 2005 is Thursday
I've developed this code
Scanner input=new Scanner(System.in);
       //Prompt the user to enter the year
       System.out.print("Enter a year:");
       int year=input.nextInt();
       //Prompt the user to enter the first day of the year
       System.out.print("Enter the first day of the year\nEX:0-Sunday,1Monday,2-Tuesday,........,6-Saturday:");
       int firstDayOfTheYear=input.nextInt();
       Calendar c=Calendar.getInstance();
    }

i don't know how can i complete this program
so, I'd be grateful if you help me
thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Display the first day of each month in a year

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10647
  • View blog
  • Posts: 39,539
  • Joined: 27-December 08

Re: Display the first day of each month in a year

Posted 19 October 2010 - 06:58 PM

Moved to Java help. Please reserve the Java Programmers forum for topical, non-help related discussion.
Was This Post Helpful? 0
  • +
  • -

#3 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: Display the first day of each month in a year

Posted 19 October 2010 - 08:37 PM

You know how many days in each month (don't forget leap years and the day that adds to February), so a solution is to simply count out each year. The 1st day is specified by the user, the pattern is M, Tu, W, Th, F, Sa, Su, repeat. Use the pattern to calculate the first day of each month. You could work out the days of interest (which numbered day, 1 - 365, does each month begin with), and modulo the resulting days by 7, then use the remainder to figure out what day of the week that is. Pretty simple.

This post has been edited by GregBrannon: 19 October 2010 - 08:39 PM

Was This Post Helpful? 1
  • +
  • -

#4 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2774
  • View blog
  • Posts: 11,729
  • Joined: 20-September 08

Re: Display the first day of each month in a year

Posted 20 October 2010 - 01:32 AM

Clue HERE
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1