Solved

How many days in a month?

Posted on 2008-10-15
1
1,301 Views
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

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
Comment
Question by:flo_the_lil_minx
1 Comment
 
LVL 1

Accepted Solution

by:
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!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i compare an object based on two fields 6 54
eclipse shortcuts 9 56
Windows 10 IE Certificate Issue 10 47
Java exception bubble up 2 18
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

831 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