Results 1 to 2 of 2
  1. #1
    kris09 is offline Member
    Join Date
    Aug 2008
    Posts
    6
    Rep Power
    0

    Default DaysAndMonth program problem Help!!

    import java.util.Scanner;

    public class DaysAndMonths {

    public static void main(String args[]) {
    Scanner myScanner = new Scanner(System.in);
    String month;

    int Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec;
    Jan = 31;
    Feb = 28;
    Mar = 31;
    Apr = 30;
    May = 31;
    Jun = 30;
    Jul = 31;
    Aug = 31;
    Sep = 30;
    Oct = 31;
    Nov = 30;
    Dec = 31;
    boolean answerYes;
    answerYes = true;
    while(answerYes == true){
    System.out.print("\nPlease type in your month: ");

    month = myScanner.nextLine();

    month = month.toLowerCase();


    System.out.print(month);
    if(month.equals("jan")) {

    System.out.print(" has ");
    System.out.print(Jan);
    System.out.print(" days");
    }
    if(month.equals("feb")) { // <---- problem starts here
    Scanner myScannerInt = new Scanner(System.in);
    int number, number2;
    System.out.print("What year is it?: ");
    number = myScannerInt.nextInt();
    number2 = number /4;





    if (number2 == ) {
    Feb = 29;
    } // <----------ends here

    System.out.print(" has ");
    System.out.print(Feb);
    System.out.print(" days");
    }
    if(month.equals("mar")) {
    System.out.print(" has ");
    System.out.print(Mar);
    System.out.print(" days");
    }
    if(month.equals("apr")) {
    System.out.print(" has ");
    System.out.print(Apr);
    System.out.print(" days");
    }
    if(month.equals("may")) {
    System.out.print(" has ");
    System.out.print(May);
    System.out.print(" days");
    }
    if(month.equals("jun")) {
    System.out.print(" has ");
    System.out.print(Jun);
    System.out.print(" days");
    }
    if(month.equals("jul")) {
    System.out.print(" has ");
    System.out.print(Jul);
    System.out.print(" days");
    }
    if(month.equals("aug")) {
    System.out.print(" has ");
    System.out.print(Aug);
    System.out.print(" days");
    }
    if(month.equals("sep")) {
    System.out.print(" has ");
    System.out.print(Sep);
    System.out.print(" days");
    }
    if(month.equals("oct")) {
    System.out.print(" has ");
    System.out.print(Oct);
    System.out.print(" days");
    }
    if(month.equals("nov")) {
    System.out.print(" has ");
    System.out.print(Nov);
    System.out.print(" days");
    }
    if(month.equals("dec")) {
    System.out.print(" has ");
    System.out.print(Dec);
    System.out.print(" days");
    }

    System.out.print("\nDo you want to continue? (Y/N): ");
    char answer;
    Scanner myScannerChar = new Scanner(System.in);
    answer = myScannerChar.findInLine(".").charAt(0);
    if(answer == 'n' || answer == 'N') {
    System.out.print("Goodbye! Please Come Again :P");
    answerYes = false;
    }

    }
    }
    }
    Here is the program i wrote i know there are a lot of if statements :p
    but my problem is on February there is a leap year and if cant figure it out when it asks for what year. Suppose you put in 2008 and to find out it is a leap year u have to divide it by four. i dont know how ur are going to compare it in the if statement please help

    - Kris

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,563
    Rep Power
    25

    Default

    how ur are going to compare it
    What is 'it' you are going to compare?
    What do you want to compute?
    Do you know how to determine if a year is a leap year? For a leap year what should be the remainder after a divide by 4?
    One way to get a remainder after a int division is to use the modulus operator. Read your text about using that.

Similar Threads

  1. Problem with my first Struts program....please help me
    By sireesha in forum Web Frameworks
    Replies: 5
    Last Post: 10-16-2011, 04:19 PM
  2. program problem
    By amith in forum AWT / Swing
    Replies: 12
    Last Post: 05-16-2008, 08:07 PM
  3. Problem with First Hibernate program
    By sireesha in forum JDBC
    Replies: 11
    Last Post: 05-05-2008, 04:19 PM
  4. Problem with my program HelloWorld
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 05:32 PM
  5. getting problem in compiling java program?
    By sathish04021984 in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 09:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •