Running compiled programs in command prompt  
Author Message
Albert





PostPosted: 2007-12-20 7:29:00 Top

java-programmer, Running compiled programs in command prompt Hi, I should know how to do what it says in the subject of this post,
but I don't. I've almost finished Sams Teach Yourself Java in 24 Hours
3rd Edition and now I need to pass some arguments to the program via
command prompt but the book only covers 1.4.

java program [arguments] when i cd it to the directory containing the
class

doesn't work.
 
Knute Johnson





PostPosted: 2007-12-20 7:35:00 Top

java-programmer >> Running compiled programs in command prompt Albert wrote:
> Hi, I should know how to do what it says in the subject of this post,
> but I don't. I've almost finished Sams Teach Yourself Java in 24 Hours
> 3rd Edition and now I need to pass some arguments to the program via
> command prompt but the book only covers 1.4.
>
> java program [arguments] when i cd it to the directory containing the
> class
>
> doesn't work.

public class test7 {
public static void main(String[] args) {
for (String arg : args)
System.out.println(arg);
}
}

C:\Documents and Settings\Knute Johnson>java test7 one two three
one
two
three

It doesn't matter which version of the JDK that you have, command line
arguments have not changed.

--

Knute Johnson
email s/nospam/knute/
 
Albert





PostPosted: 2007-12-20 7:52:00 Top

java-programmer >> Running compiled programs in command prompt On Dec 20, 10:35 am, Knute Johnson <email***@***.com>
wrote:
> Albert wrote:
> > Hi, I should know how to do what it says in the subject of this post,
> > but I don't. I've almost finished Sams Teach Yourself Java in 24 Hours
> > 3rd Edition and now I need to pass some arguments to the program via
> > command prompt but the book only covers 1.4.
>
> > java program [arguments] when i cd it to the directory containing the
> > class
>
> > doesn't work.
>
> public class test7 {
> public static void main(String[] args) {
> for (String arg : args)
> System.out.println(arg);
> }
>
> }
>
> C:\Documents and Settings\Knute Johnson>java test7 one two three
> one
> two
> three
>
> It doesn't matter which version of the JDK that you have, command line
> arguments have not changed.
>
> --
>
> Knute Johnson
> email s/nospam/knute/

I can't get this to work:

class DivideNumbers {
public static void main(String[] arguments) {
if (arguments.length == 2) {
int result = 0;
try {
result = Integer.parseInt(arguments[0]) /
Integer.parseInt(arguments[1]);
System.out.println(arguments[0] + " divided by " +
arguments[1] + " equals " + result);
}
catch (NumberFormatException e) {
System.out.println("Both numbers must be numbers");
}
catch (ArithmeticException e) {
System.out.println("You cannot divide by zero.");
}
}
}
}

java dividenumbers 2 2
 
 
Patricia Shanahan





PostPosted: 2007-12-20 8:02:00 Top

java-programmer >> Running compiled programs in command prompt Albert wrote:
> On Dec 20, 10:35 am, Knute Johnson <email***@***.com>
> wrote:
>> Albert wrote:
>>> Hi, I should know how to do what it says in the subject of this post,
>>> but I don't. I've almost finished Sams Teach Yourself Java in 24 Hours
>>> 3rd Edition and now I need to pass some arguments to the program via
>>> command prompt but the book only covers 1.4.
>>> java program [arguments] when i cd it to the directory containing the
>>> class
>>> doesn't work.
>> public class test7 {
>> public static void main(String[] args) {
>> for (String arg : args)
>> System.out.println(arg);
>> }
>>
>> }
>>
>> C:\Documents and Settings\Knute Johnson>java test7 one two three
>> one
>> two
>> three
>>
>> It doesn't matter which version of the JDK that you have, command line
>> arguments have not changed.
>>
>> --
>>
>> Knute Johnson
>> email s/nospam/knute/
>
> I can't get this to work:
>
> class DivideNumbers {
...
>
> java dividenumbers 2 2

Have you tried "java DivideNumbers 2 2"?

Patricia
 
 
Albert





PostPosted: 2007-12-20 14:09:00 Top

java-programmer >> Running compiled programs in command prompt On Dec 20, 11:01 am, Patricia Shanahan <email***@***.com> wrote:
> Albert wrote:
> > On Dec 20, 10:35 am, Knute Johnson <email***@***.com>
> > wrote:
> >> Albert wrote:
> >>> Hi, I should know how to do what it says in the subject of this post,
> >>> but I don't. I've almost finished Sams Teach Yourself Java in 24 Hours
> >>> 3rd Edition and now I need to pass some arguments to the program via
> >>> command prompt but the book only covers 1.4.
> >>> java program [arguments] when i cd it to the directory containing the
> >>> class
> >>> doesn't work.
> >> public class test7 {
> >> public static void main(String[] args) {
> >> for (String arg : args)
> >> System.out.println(arg);
> >> }
>
> >> }
>
> >> C:\Documents and Settings\Knute Johnson>java test7 one two three
> >> one
> >> two
> >> three
>
> >> It doesn't matter which version of the JDK that you have, command line
> >> arguments have not changed.
>
> >> --
>
> >> Knute Johnson
> >> email s/nospam/knute/
>
> > I can't get this to work:
>
> > class DivideNumbers {
> ...
>
> > java dividenumbers 2 2
>
> Have you tried "java DivideNumbers 2 2"?
>
> Patricia

Thanks a lot. Problem solved
 
 
Lew





PostPosted: 2007-12-20 21:49:00 Top

java-programmer >> Running compiled programs in command prompt Albert wrote:
>>> I can't get this to work:
>>> class DivideNumbers {
>> ...
>>
>>> java dividenumbers 2 2

Patricia Shanahan wrote:
>> Have you tried "java DivideNumbers 2 2"?

Albert wrote:
> Thanks a lot. Problem solved

That was it, wasn't it?

--
Lew
This post contains one request for information.