Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

Running compiled programs in command prompt

Thread view: 
Albert - 19 Dec 2007 23:29 GMT
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 - 19 Dec 2007 23:35 GMT
> 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
[quoted text clipped - 5 lines]
>
> 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.

Signature

Knute Johnson
email s/nospam/knute/

Albert - 19 Dec 2007 23:52 GMT
> > 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
[quoted text clipped - 26 lines]
> 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
Arne Vajhøj - 19 Dec 2007 23:58 GMT
> I can't get this to work:
>
[quoted text clipped - 19 lines]
>
> java dividenumbers 2 2

It would have been a bit easier to troubleshoot if you
had posted the error !

But a guess:

java -cp . dividenumbers 2 2

Arne
Patricia Shanahan - 20 Dec 2007 00:01 GMT
>>> 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
[quoted text clipped - 27 lines]
>
> class DivideNumbers {
...

> java dividenumbers 2 2

Have you tried "java DivideNumbers 2 2"?

Patricia
Albert - 20 Dec 2007 06:09 GMT
> >>> 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
[quoted text clipped - 34 lines]
>
> Patricia

Thanks a lot. Problem solved
Lew - 20 Dec 2007 13:48 GMT
>>> I can't get this to work:
>>> class DivideNumbers {
>> ...
>>
>>> java dividenumbers 2 2

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

> Thanks a lot. Problem solved

That was it, wasn't it?

Signature

Lew
This post contains one request for information.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.