Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Questions!

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Questions!

    package javaapplication2;
    class DayCounter{
    public static void main(String[] arguments){
    int yearIn = 2013;
    int monthIn = 12;

    if (arguments.length < 0)
    monthIn = Integer.parseInt(arguments[0]);
    if( arguments.length < 1)
    yearIn = Integer.parseInt(arguments[1]);
    System.out.println( monthIn + "/" + yearIn + " has "
    + countDays(monthIn, yearIn) + "days.");

    }


    This is just a part of the whole java file/program that I don't understand.
    So my question is, what length are they referring to at:
    if (arguments.length < 0)
    if (arguments.length < 1) ?

    Why did the person choose 0 and 1?


    Also, what is "Integer.parseInt" and does (arguments[0] ) mean the monthIn will be stored in the "String[] arguments"?
    If so, then what's the point of that?

    monthIn = Integer.parseInt(arguments[0]);
    yearIn = Integer.parseInt(arguments[1]);




    I know that I have many questions, but please answer this question too:

    When I type in statements and expressions in the main method, do they get stored inside the main method? (In the "String[] arguments" in this case)

    Please answer my questions
    I'm self-studying Java with a book that doesn't explain things very well.
    Thanks!


  2. #2
    Junior Member
    Join Date
    May 2013
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Questions!

    Is there an input to this code in "main". This doesn't make much sense. This Java - parseInt() Method talks about parseInt.

    I recommend "Head First Java" for an excellent book that you can buy used. I would like to see the rest of the program if it's not too big. thx.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Questions!

    package javaapplication2;
    class DayCounter{
    public static void main(String[] arguments){
    int yearIn = 2013;
    int monthIn = 12;

    System.out.println( arguments.length );


    if (arguments.length < 20000)
    monthIn = Integer.parseInt(arguments[0]);
    if( arguments.length < 2)
    yearIn = Integer.parseInt(arguments[1]);
    System.out.println( monthIn + "/" + yearIn + " has "
    + countDays(monthIn, yearIn) + "days.");

    }

    static int countDays(int month, int year) {
    int count = -1;
    switch (month) {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
    count = 31;
    break;
    case 4:
    case 6:
    case 9:
    case 11:
    count = 30;
    break;
    case 2:
    if ( year % 4 == 0 )
    count = 29;
    else count = 28;
    if (( year % 100 == 0) & year % 400 !=0)
    count = 28;
    }

    return count;


    }
    }

Similar Threads

  1. List of my Java3D Questions, and Proguard questions
    By Zachary1234 in forum Java SE APIs
    Replies: 0
    Last Post: November 16th, 2012, 09:40 PM
  2. A few questions
    By elatechris777 in forum Java Theory & Questions
    Replies: 2
    Last Post: May 5th, 2012, 06:33 PM
  3. Need help with some questions!
    By goha14 in forum Java Theory & Questions
    Replies: 6
    Last Post: March 27th, 2012, 08:01 PM
  4. A few questions
    By adenverd in forum Java Theory & Questions
    Replies: 3
    Last Post: May 26th, 2010, 03:34 AM
  5. [SOLVED] Some serious questions,
    By Time in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 17th, 2010, 02:52 AM