Solved

# How many days in a month?

Posted on 2008-10-15
1,299 Views
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");

}

}

}
``````
0
Question by:flo_the_lil_minx
1 Comment

LVL 1

Accepted Solution

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

## Join & Write a Comment Already a member? Login.

### Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

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

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

#### Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!