什么是“字符串参数 []"?主要方法Java中的参数
我刚刚开始用 Java 编写程序.下面的Java代码是什么意思?
I'm just beginning to write programs in Java. What does the following Java code mean?
public static void main(String[] args)
什么是
String[] args?你什么时候使用这些
args?源代码和/或示例优于抽象解释
Source code and/or examples are preferred over abstract explanations
推荐答案
在 Java 中
args包含提供的 命令行参数 作为String对象的数组.In Java
argscontains the supplied command-line arguments as an array ofStringobjects.换句话说,如果你以
java MyProgram one two运行你的程序,那么args将包含["one", "two"].In other words, if you run your program as
java MyProgram one twothenargswill contain["one", "two"].如果你想输出
args的内容,你可以像这样循环遍历它们...If you wanted to output the contents of
args, you can just loop through them like this...public class ArgumentExample { public static void main(String[] args) { for(int i = 0; i < args.length; i++) { System.out.println(args[i]); } } }
相关文章