什么是“String args []”?主方法Java中的参数 [英] What is "String args[]"? parameter in main method Java

查看:149
本文介绍了什么是“String args []”?主方法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 args contains the supplied command-line arguments as an array of String objects.

    换句话说,如果您运行程序为 java MyProgram一两然后 args 将包含 [one ,两个]

    In other words, if you run your program as java MyProgram one two then args will 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]);
            }
        }
    }
    

    这篇关于什么是“String args []”?主方法Java中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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