Code subject: pass parameters to main method args[] variables
Posted: Thu Feb 05, 2009 12:02 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 57 time
Pass parameters to main method args[] variables :
Code:
public class Passparam{ public static void main (String [] args) { System.out.println("Number of arguments passed are " + args.length); System.out.println("The First " + args[0]); System.out.println("The second " + args[1]); } }
Code:
java Passparam code miles
The output is :
Code:
Number of arguments passed are 2 The First code The second miles
You can change the name of parameter args ,but it must be of type String
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )