command line arguments

Discussion in 'Java' started by summer_haven, Jul 14, 2006.

  1. summer_haven

    summer_haven Guest

    hello all..
    im new to java, starting year one next year in university and going
    through some questions that have been used in the past for newbies..

    i need help on a command line question. basically i have written a
    program (works on textpad) but wish for it to run on command prompt
    (windows xp) so that i simply type:

    java calculation 0 10.0 2 ... so it outputs the answer (in this case
    5.0). however after attempting this, only error messages appear
    (NoClassDefFoundError:calculation)

    here is the code:

    import java.util.Scanner;
    import java.io.*;

    public class Calculation {
    public static void main (String[]args)
    {
    for (int i = 0; i < args.length; i++)
    System.out.println(args);

    Scanner in = new Scanner(System.in);

    System.out.println("Please Enter Velocity - in meters");
    double v = in.nextDouble();

    System.out.println("Please Enter velocity - in meters/seconds");
    double u = in.nextDouble();

    System.out.println("Please Enter Time - in seconds");
    double t = in.nextDouble();


    {
    System.out.println("The acceleration is " + ((v-u)/t));
    }
    }

    }

    thanks for any help!
    Sara
     
    summer_haven, Jul 14, 2006
    #1
    1. Advertising

  2. summer_haven wrote:
    > hello all..
    > im new to java, starting year one next year in university and going
    > through some questions that have been used in the past for newbies..
    >
    > i need help on a command line question. basically i have written a
    > program (works on textpad) but wish for it to run on command prompt
    > (windows xp) so that i simply type:
    >
    > java calculation ..


    Java is case sensitive, so that needs to be..

    > public class Calculation {


    java Calculation

    ...if you are working from the directory that contains this
    'default package' class, you should be able to start it with
    either..
    java Calculation
    ...or..
    java -classpath . Calculation

    The second form explicitly adds the current directory ('.')
    to the classpath.

    > thanks for any help!


    A better group for those learning Java is comp.lang.java.help

    HTH

    Andrew T.
     
    Andrew Thompson, Jul 14, 2006
    #2
    1. Advertising

  3. summer_haven

    Joe Guest

    summer_haven wrote:
    >[snip]
    > i need help on a command line question. basically i have written a
    > program (works on textpad) but wish for it to run on command prompt
    > (windows xp) so that i simply type:
    >
    > java calculation 0 10.0 2 ... so it outputs the answer (in this case
    > 5.0). however after attempting this, only error messages appear
    > (NoClassDefFoundError:calculation)
    >
    > here is the code:
    >
    > import java.util.Scanner;
    > import java.io.*;
    >
    > public class Calculation {
    > [snip]



    For starters, since Java is case sensitive try capitalizing Calculation
    on the command line. Also try setting the classpath argument to your
    current directory (assuming you are running from the directory the
    Calculation.class file is in). This would read:

    java -cp . Calculation 0 10.0 2

    --Joe
     
    Joe, Jul 14, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Kay
    Replies:
    1
    Views:
    485
    J├╝rgen Exner
    May 18, 2004
  2. Ahmed Moustafa

    Parser for command line arguments?

    Ahmed Moustafa, Aug 21, 2003, in forum: Java
    Replies:
    0
    Views:
    390
    Ahmed Moustafa
    Aug 21, 2003
  3. SC
    Replies:
    2
    Views:
    660
    Michiel Salters
    May 5, 2004
  4. Ashe Corven

    command line arguments

    Ashe Corven, May 8, 2004, in forum: C++
    Replies:
    3
    Views:
    528
    Francis Glassborow
    May 8, 2004
  5. Replies:
    4
    Views:
    1,716
    Terry Hancock
    Apr 23, 2005
Loading...

Share This Page