command line arguments

S

summer_haven

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
 
A

Andrew Thompson

summer_haven said:
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.
 
J

Joe

summer_haven said:
[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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top