Results 1 to 6 of 6
  1. #1
    mustachMan is offline Member
    Join Date
    Dec 2009
    Posts
    33
    Rep Power
    0

    Post Command-Line Arguments

    on one example program it says to put a command line argument to see the program run and i dont know where to put it?
    do you have to write it in the code?
    Java Code:
    class YearDisplayer {
        public static void main(String[] arguments) {
            int year = 2000;
            if (arguments.length > 0)
                year = Integer.parseInt(arguments[0]);
            for (int month = 1; month < 13; month++)
                for (int day = 1; day <= countDays(month, year); day++)
                    System.out.println(month + "/" + day + "/" + year);
        }
    
        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;
        }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    If you call YearDisplayer on the command line with the java command, put the arguments there:

    java YearDisplayer argument1 argument2

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Are you working on command prompt or on an IDE? Different IDEs have different techniques to assign command line parameters, but the concept is the same.

  4. #4
    mustachMan is offline Member
    Join Date
    Dec 2009
    Posts
    33
    Rep Power
    0

    Default

    If you call YearDisplayer on the command line with the java command, put the arguments there:
    I want to know where is the command line?

    and I am using Eclipse

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    If you're using Eclipse, then it's buried in Eclipse, but you can find it by going to the run menu and searching for it under Run Configurations, then Program Arguments.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by mustachMan View Post
    I want to know where is the command line?
    Before the use of Eclipse, have you ever tried to write a simple code/application on Notepad and run it on command prompt with arguments?

Similar Threads

  1. java command line arguments
    By Vipul03 in forum Advanced Java
    Replies: 10
    Last Post: 02-25-2010, 11:12 AM
  2. Command Line Arguments
    By Nakira in forum NetBeans
    Replies: 10
    Last Post: 02-04-2010, 04:45 PM
  3. arguments in command-line
    By girlet18 in forum New To Java
    Replies: 2
    Last Post: 01-21-2010, 03:05 PM
  4. Command line arguments help
    By may88 in forum New To Java
    Replies: 8
    Last Post: 12-08-2009, 02:20 PM
  5. [SOLVED] command line arguments using IDE
    By sandeepsai39 in forum New To Java
    Replies: 5
    Last Post: 03-12-2009, 08:19 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
  •