java - 使用 String[] args 传递参数
问题描述
我强烈怀疑我在这里很愚蠢,但我以前从未见过任何人这样做。在本课程作业中,他们使用 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_bottom
或myprogram.exe gate_top
条件将被触发
推荐阅读
- excel - 对多维 SSAS 的 DAX 查询不正确
- css - 没有 React 的 Material-UI / 只有普通的 HTML、CSS 和 JS?可能的?
- locust - Locust 在没有 docker 用户界面的分布式模式下不生成 failures.csv 和 expections.csv
- html - 有什么方法可以访问
页面内的标签? - vb.net - 按列分组并显示所有列值linq
- c# - 如何从soap服务c#中读取数据
- ios - EAGLContext presentRenderbuffer 导致死锁
- php - 一个函数的用户变量,在另一个函数中
- logging - 在 GCP 中更改 Stackdriver Logging 日志的标头
- python - 在Django(Python)中多次传递参数失败