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[i]);
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
Andrew Thompson - 14 Jul 2006 13:40 GMT
> hello all..
> im new to java, starting year one next year in university and going
[quoted text clipped - 5 lines]
>
> 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.
Joe - 14 Jul 2006 13:44 GMT
>[snip]
> i need help on a command line question. basically i have written a
[quoted text clipped - 12 lines]
> 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