使用 String[] 参数传递参数



我强烈怀疑我在这里很愚蠢,但我以前从未见过任何人这样做。在本课程中,他们不是声明变量,而是使用在 main 中声明的字符串数组参数。

static public void main(String[] args) {
RandomAccessFile admin;

byte init[] = {0};
if (args.length != 1)
System.err.println("usage: java {gate_bottom,gate_top}");

我的指示是 "为此,您需要指定一个参数。 参数应为 gate_bottom 或gate_top">

我应该在哪里指定参数,以便 args 包含某些内容?

if(args[0].equals("gate_bottom"))
else if(args[0].equals("gate_top")) 

因此,当您像myprogram.exe gate_bottommyprogram.exe gate_top调用程序时,将触发条件

最新更新