return 来自命令行程序的参数
return parameters from command line program
我试图在 java 中通过命令行传递一个字符串,但它 returns 只有第一个值,即 args[0]
以下是我所做的
public class CommandLine
{
public static void main(String[] args)
{
int i;
i = args[0].length(); //throws error here if args.length();
System.out.println(i); //checking length, return with args[0] only
while(i>0)
{
System.out.println(args[0]);
i++;
}
}
}
What should I do to improve this and make it working?
以下是一些需要解决的问题
在您的逻辑命令行中,参数长度取错了。
循环条件不适合您的要求,而且它是一个无限循环或永不结束的循环,会降低 code.Should 代码中永远不要使用无限循环的性能。
3.you 每次在循环内打印相同的索引,即 ..args[0]。
代码:
public static void main(String[] args)
{
int i=0;
int len = args.length; //use length only in this case;
System.out.println(len); // this will return it properly now
while(i<len)
{
System.out.println(args[i]);
i++;
}
}
我试图在 java 中通过命令行传递一个字符串,但它 returns 只有第一个值,即 args[0]
以下是我所做的
public class CommandLine
{
public static void main(String[] args)
{
int i;
i = args[0].length(); //throws error here if args.length();
System.out.println(i); //checking length, return with args[0] only
while(i>0)
{
System.out.println(args[0]);
i++;
}
}
}
What should I do to improve this and make it working?
以下是一些需要解决的问题
在您的逻辑命令行中,参数长度取错了。
循环条件不适合您的要求,而且它是一个无限循环或永不结束的循环,会降低 code.Should 代码中永远不要使用无限循环的性能。
3.you 每次在循环内打印相同的索引,即 ..args[0]。
代码:
public static void main(String[] args)
{
int i=0;
int len = args.length; //use length only in this case;
System.out.println(len); // this will return it properly now
while(i<len)
{
System.out.println(args[i]);
i++;
}
}