public class Test{ public static void main(String[] args){ for(int i = 0; i < args.length; i++) System.out.println(args[i]); } }java Test str1 str2 输出: str1 str2 可见,args是提供给main的参数
看: public class q{ public static void main(String[] args){ System.out.println("--------"); } } 再看: public class q{ public static void main(String[] d){ System.out.println("--------"); } } 一样的。
你可以换成其他的也行。
public static void main(String[] args){
for(int i = 0; i < args.length; i++)
System.out.println(args[i]);
}
}java Test str1 str2
输出:
str1
str2
可见,args是提供给main的参数
javac -d temp.java
这里,-d 就是一个命令行参数
javac -d . temp.java
-d和. 都是命令行参数
告诉编译器,根据不同的参数,做不同的处理
你自己的程序里也可以加这些东西
就是通过args[]数组里的东西来判定的
public class q{
public static void main(String[] args){
System.out.println("--------");
}
}
再看:
public class q{
public static void main(String[] d){
System.out.println("--------");
}
}
一样的。