Results 1 to 5 of 5
  1. #1
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

    Default list values in a number of steps given as a command line argument

    Hi there, i have created a program which lists sin values from a specific value to another value when given as command line argument. For example; java SinTable 0 10 90 would produce a table of sin values from 0 to 90 in STEPS of 10.
    I cant get the steps of 10 to work:

    int sinValue1 = Integer.parseInt(args[0]);
    int sinValue2 = Integer.parseInt(args[2]);
    int numberOfSteps = Integer.parseInt(args[1]);


    System.out.println("-----------------------------------------");
    System.out.println("| Sin Table from " + args[0] + " to "
    + args[2] + " in steps of " + args[1]
    + " |");
    System.out.println("-----------------------------------------");


    for (int index = 0; index < numberOfSteps; index++)
    {
    System.out.println("| sin(" + index + ")" + "="
    + Math.sin(index));


    Any help?

    Regards

    Shyam

  2. #2
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    Your "for" loop only goes from 0 to numberOfSteps. Don't you mean for it to go from...sinValue1 to sinValue2 and then increment by numberOfSteps?
    Sincerely, Joshua Green
    Please REP if I help :)

  3. #3
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

    Default

    Yeah! Thats what i meant to do. So do i just change the int index = sinValue1?

  4. #4
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    Quote Originally Posted by Shyamz1 View Post
    Yeah! Thats what i meant to do. So do i just change the int index = sinValue1?

    Exactly, it should look something like:

    Java Code:
    for (int index = sinValue1; index <= sinValue2; index += numberOfSteps)
    {
         System.out.println("| sin(" + index + ")" + "=" + Math.sin(index));
    }
    Sincerely, Joshua Green
    Please REP if I help :)

  5. #5
    Shyamz1 is offline Member
    Join Date
    Oct 2010
    Posts
    56
    Rep Power
    0

Similar Threads

  1. Command line argument
    By denisatandi in forum New To Java
    Replies: 8
    Last Post: 10-17-2012, 12:37 AM
  2. Maximum length of Command Line Argument
    By balamurugan.murthy in forum Advanced Java
    Replies: 11
    Last Post: 05-21-2010, 05:45 PM
  3. Command line argument help...
    By arson09 in forum New To Java
    Replies: 4
    Last Post: 05-06-2010, 06:49 PM
  4. Command Line Argument
    By right2001 in forum New To Java
    Replies: 6
    Last Post: 02-17-2009, 03:08 PM
  5. Parsing Argument Values
    By vipvan2000 in forum New To Java
    Replies: 1
    Last Post: 03-06-2008, 12:01 PM

Posting Permissions

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