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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 7 of 7

Thread: got a question

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default got a question

    i have to write a program that gets the month and year from the user. and then i have to print the number of days in a year and display if the year is a leap year. i have the leap year part down. what would i have to do to display the number of days for the month the user chooses. and how i would make feb have that extra day if it is a leap year. hope this makes sense thank you in advance


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: got a question

    what would i have to do to display the number of days
    You could use the System.out.println() method to display the number of days on the console.
    how i would make feb have that extra day if it is a leap year
    Use 29 days for a leap year.

    Are these really your questions?

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got a question

    ok my question is they enter the month. how do i convert there answer they chose, eg april, to number of days in that month. i figured out the leap year part i believe. but how would i do the month? and yes these are really my questions. i just started working in java.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: got a question

    What data structures and coding techniques do you know about?
    The simplest way to convert a String with the name of a month to an int value for the number of days would be an if statement with a compound condition. Use one of the String class's methods to compare what the user entered to each month name. With more knowledge put the names in an array and use a loop.

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got a question

    i know how to use the if statements, loops, boolean type, switch statments. just baisc stuff we are about to start learning meathods. ok so baiscally i have to assign each month as the number of days. so like int jan = 31;
    and use an if statment for the month of feb if it is a leap year?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: got a question

    There are three different groups of months when you consider the number of days in a month.
    Some have 30, some have 31 and one has either 28 or 29.
    Use if statements to see which group the given month is in.

  7. #7
    Junior Member
    Join Date
    Feb 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: got a question

    oh ok that would make it way better than assigning each one as a variable. thank you. i will play around with that and see if i can get it right