• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1311
  • Last Modified:

How many days in a month?

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

TIA Flo
// Days in Month
 
import java.util.*;
 
public class DaysInMonth
 
{
 
  public static void main (String[]args)
 
  {
    //create scanner from keyboard
    
    Scanner myKeyboard = new Scanner (System.in);
    
    //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");
          }
          else          
          {
          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");
    }
    else
    {
    System.out.print("There are 31 days");
    }
   }
  }

Open in new window

0
flo_the_lil_minx
Asked:
flo_the_lil_minx
1 Solution
 
flo_the_lil_minxAuthor Commented:
It's ok, I fixed it myself.  I got it to ask the month before the year and it worked.  YAY!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now