/* command line arguments in C */
void main(int argc, char** argv)
{
char name[128];
int age = 0;
if (argc >= 2) {
strcpy(name, argv[1]);
age = atoi(argv[2]);
printf("%s, name = %s, age = %d\n", argv[0], name, age);
}
}
~>person.exe Park 20
argv[0] = “person.exe”
argv[1] = “Park”
argv[2] = “20”
// command line arguments in java
public class Person {
public static void main(String[] args) {
String name = "";
int age = 0;
if (args.length >= 2) {
name = args[0];
age = Integer.parseInt(args[1]);
System.out.printf("name = %s, age = %d\n", name, age);
}
}
}
~>java Person Park 30
args[0] = “Park”
args[1] = “30”