for (int i = 0; i < args.length; i++) { System.out.println(args[i]); }
public class Test{ public static void main(String[] args){ for(int i=0;i<args.length;i++){ System.out.println(args[i]); } } }
core java 中有个简单的例子,代码如下:public class Message { public static void main(String[] args) { if (args[0].equals("-h")) System.out.print("Hello,"); else if (args[0].equals("-g")) System.out.print("Goodbye,"); // print the other command-line arguments for (int i = 1; i < args.length; i++) System.out.print(" " + a[i]); System.out.println("!"); } } If the program is called asjava Message -g cruel worldthen the args array has the following contents:args[0]: "-g" args[1]: "cruel" args[2]: "world"The program prints the messageGoodbye, cruel world! 类似的例子,在百度和Google上不少,楼主可以搜索“java 命令行参数”!多看几个例子明白的透彻一点。good luck!!!
package think;public class ArgsTest { public static void main(String args[]) { int SIZE = 5; for (int i = 0; i < SIZE; i++) { System.out.print(args[i]+" "); } }}eclipse 运行情况:Debug->Arguments 框里面填写 1 2 3 4 5(用空格隔开) 输出结果 : 1 2 3 4 5 命令提示符下 javac ArgsTest.java java ArgsTest 1 2 3 4 5 输出结果 :1 2 3 4 5 我写的很清楚了。仔细敲下就可以了。祝你学习愉快!
public class ArgsTest{ public static void main(String [] args){ for(int i=0;i<args.length;i++){ System.out.println(args[i]+" "); } } }在运行里面->cmd->可以输入参数试下
命令行是黑白屏吧?String[] str = new String[]{10,2,4,6,8,7}
for(int i=0;i<str.length;i++){
System.out.println(str[i]);
}
对
for (int i = 0; i < args.length; i++) {
System.out.println(args[i]);
}
public class Test{
public static void main(String[] args){
for(int i=0;i<args.length;i++){
System.out.println(args[i]);
}
}
}
{
public static void main(String[] args)
{
if (args[0].equals("-h"))
System.out.print("Hello,");
else if (args[0].equals("-g"))
System.out.print("Goodbye,");
// print the other command-line arguments
for (int i = 1; i < args.length; i++)
System.out.print(" " + a[i]);
System.out.println("!");
}
}
If the program is called asjava Message -g cruel worldthen the args array has the following contents:args[0]: "-g"
args[1]: "cruel"
args[2]: "world"The program prints the messageGoodbye, cruel world!
类似的例子,在百度和Google上不少,楼主可以搜索“java 命令行参数”!多看几个例子明白的透彻一点。good luck!!!
package think;public class ArgsTest { public static void main(String args[]) {
int SIZE = 5;
for (int i = 0; i < SIZE; i++) {
System.out.print(args[i]+" ");
}
}}eclipse 运行情况:Debug->Arguments 框里面填写 1 2 3 4 5(用空格隔开)
输出结果 : 1 2 3 4 5
命令提示符下 javac ArgsTest.java
java ArgsTest 1 2 3 4 5
输出结果 :1 2 3 4 5
我写的很清楚了。仔细敲下就可以了。祝你学习愉快!
public static void main(String [] args){
for(int i=0;i<args.length;i++){
System.out.println(args[i]+" ");
}
}
}在运行里面->cmd->可以输入参数试下
右键runas run.. 选arguments选项输入参数再运行就可以了