How many days in a month?

Posted on 2008-10-15
Last Modified: 2013-11-23
I have to write a script that will tell the user how many days are in a certain month in the year they have entered.  The exercise is using nested selection.  Where am I going wrong here?  It compiles ok but when I enter the year it doesn't ask me for the month, it just tells me there are 31 days

// Days in Month
import java.util.*;
public class DaysInMonth
  public static void main (String[]args)
    //create scanner from keyboard
    Scanner myKeyboard = new Scanner (;
    //prompt for year
    System.out.print("Please enter the year ");
    int year = myKeyboard.nextInt();
    //prompt for month
    System.out.print("Please enter the month");
    String month = myKeyboard.nextLine();
    //Determine if it is a leap year
    boolean isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    //calculate and return result
    if (month.equals("february"))
          if (isLeapYear = true)
          System.out.print("There are 29 days");
          System.out.print("There are 28 days");
    else if (month.equals("november"))
    System.out.print("There are 30 days");
    else if (month.equals("april"))
    System.out.print("There are 30 days");
    else if (month.equals("june"))
    System.out.print("There are 30 days");
    System.out.print("There are 31 days");

Open in new window

Question by:flo_the_lil_minx
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

flo_the_lil_minx earned 0 total points
ID: 22724979
It's ok, I fixed it myself.  I got it to ask the month before the year and it worked.  YAY!

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question