命令行传递参数
有时候你希望运行一个程序时候再传递给它消息。这要靠传递命令行参数给main()函数实现。
命令行参数是在执行程序时候紧跟在程序名字后面的信息。
public class CommandLine {
public static void main(String args[]){
for(int i=0; i<args.length; i++){
System.out.println("args [" + i + "]: " + args[i]);
}
}
}
运用命令行敲以下命令:
java CommandLine this is a command line 200 -100
运行结果如下:
args[0]: this
args[1]: is
args[2]: a
args[3]: command
args[4]: line
args[5]: 200
args[6]: -100

浙公网安备 33010602011771号