java主方法:
public static void main(String[] args) {
//code
}
其中参数String [] args
为一个字符数组,表示命令行参数,如下图:
代码如下:
public class 主方法参数意义 {
public static void main(String[] args) {
for(int i=0;i<args.length;i++)
//打印传入的参数
System.out.println("参数"+(i+1)+": "+args[i]);
}
当需要在命令行向主函数传入参数时,args就起作用啦。如果不写如果不写则会报错:
一般按照规定写就可以,只有在咋Dos下需要向主函数传递参数时才会用到args。