var country = flag.String("country", "Canada", "user home country")
flag.Parse()
fmt.Println("country is", *country)
country has pointer type *string. Call Parse only once, after all flags are defined and before flags are read. Flags must be passed before the non-flag arguments.
publicstaticvoidmain(String[] args) {
String s;
int i, n = args.length;
for (i = 0; i < n; ++i)
if (args[i].equals("-country"))
break;
s = ++i < n ? args[i] : "Canada";
out.println(s);
}
public static void main(String[] args) {
String s;
int i, n = args.length;
for (i = 0; i < n; ++i)
if (args[i].equals("-country"))
break;
s = ++i < n ? args[i] : "Canada";
out.println(s);
}