我们如何使用命令提示符和记事本将参数传递给JAVA中的main函数? [英] How can we pass arguments to the main function in JAVA using command prompt and notepad?
本文介绍了我们如何使用命令提示符和记事本将参数传递给JAVA中的main函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天,我正在学习如何在没有IDE的情况下仅在记事本上将参数传递给JAVA中的主函数,我遇到了只能使用命令行参数来完成的事情.我的问题是如何?
Today, I was learning about passing arguments to the main function in JAVA , with no IDE , only on Notepad and I encountered that it can only be done using command line arguments . My question is how?
推荐答案
我们只需打开cmd即可完成此操作,并编写
We can do this simply by opening the cmd , and writing the
javac file_name.java
javac file_name.java
java file_name [参数集] ...
java file_name [set of arguments]...
假设程序像
class temp
{
public static void main(String[] args)
{
System.out.println(args[0]);
System.out.println(args[1]);
//And so on
// As per the length of args
}
}
如果我们通过了
javac temp.java
javac temp.java
java temp_name你好世界
java temp_name hello world
它将输出为
你好
世界
这篇关于我们如何使用命令提示符和记事本将参数传递给JAVA中的main函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文