如何使用参数在cmd中运行java程序 [英] How to run a java program in cmd with arguments

查看:38
本文介绍了如何使用参数在cmd中运行java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个初学者问题.我正在尝试从带有参数的 cmd 运行 java 程序.这是我的课:

公共类测试{公共静态无效主(字符串 [] args){System.out.println("这是一个测试");System.out.println(args.length);}}

我可以在没有参数的情况下成功运行它.我如何将例如 5 和 6 作为参数放入我的程序中?

我找到了运行程序的所有其他答案.我已经知道该怎么做了.我无法找到如何使用参数运行程序.

解决方案

java Test arg1 arg2 arg3 ...

java 测试 "arg1 arg2 arg3" ...

此处有更多详细信息命令行参数

This is a beginner question. I am trying to run a java program from cmd with arguments. This is my class:

public class Test{
    public static void main(String[] args){
        System.out.println("This is a test");
        System.out.println(args.length);
    }
}

I can run it without arguments successfully. How can I put for example 5 and 6 as arguments in my program?

All the other answers I found where just to run the program. I already know how to do that. I was not able to find how to run the program using arguments.

解决方案

java Test arg1 arg2 arg3 ...

or

java Test "arg1 arg2 arg3" ...

More details here Command-Line Arguments

这篇关于如何使用参数在cmd中运行java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆