Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I pass a variable from the command prompt to the Class 1

Status
Not open for further replies.

faust13

Programmer
Aug 7, 2001
176
US
I want to be able to pass in a variable at the command prompt and use that variable inside of the class. Any suggestions?

example

Command prompt:
c:\java myClass cmdLnVar

Inside the class:
var1 = cmdLnVar;

Can you do this? ----------------------------------------
Is George Lucas Kidding...
 
Command-line parameters are passed in the String array parameter of main(). So a quick example program would be:
Code:
public class myClass {
  public static void main(String args[]) {
    /* Display all command-line parameters */
      for (int i=0; i < args.length; i++) {
        System.out.println(&quot;Command &quot; + i + &quot;:  &quot; + args[i]);
      }
  }
}
This should give you more than enough to go on to solve your problem. Wushutwist
 
Thank you. ----------------------------------------
Is George Lucas Kidding...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top