命令行传参
public class HelloWorld {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++)
System.out.println(args[i]);
}
}
命令行
cmd C:\Users\98317\Desktop\MyWork\Java\JavaSE\src>javac HelloWorld.java
cmd C:\Users\98317\Desktop\MyWork\Java\JavaSE\src>java HelloWorld this is a world
输出结果:
this
is
a
world
可变参数
public class HelloWorld {
public static void main(String[] args) {
test(1, 2, 3, 4);
}
public static void test(int x, int... i) { //i必须在最后面
System.out.println(i[0]);
System.out.println(i[1]);
System.out.println(i[2]);
System.out.println(i[3]);
}
}
本质是数组
输出结果:
1
2
3
4