简体   繁体   English

我们如何在java的命令行参数中逐行输入

[英]how can we take input line by line in command line argument in java

I want to write a command-line argument program in java where the input one on each line rather than spaces.我想在java中编写一个命令行参数程序,其中每行输入一个而不是空格。 this is how I want to take input as command line argument这就是我想将输入作为命令行参数的方式

like 1 then the next input will be at next line of console
Scanner scan = new Scanner(System.in);
String myLine = scan.nextLine();

You'll find more information on their implementation in the API Documentation for java.util.Scanner您可以在java.util.ScannerAPI 文档找到有关其实现的更多信息

In this example, we are printing all the arguments passed from the command-line.在这个例子中,我们打印了从命令行传递的所有参数。 For this purpose, we have traversed the array using for loop.为此,我们使用 for 循环遍历了数组。

public static void main(String args[]){  

  for(int i=0;i<args.length;i++)  {
    System.out.println(args[i]);  
  }
} 

compile by > javac A.java编译通过 > javac A.java

run by >由 > 运行

java A sonoo \
jaiswal \
1 \
3 \
abc  
Output:sonoo
       jaiswal
       1
       3
       abc

For more detail referre https://www.javatpoint.com/command-line-argument有关更多详细信息,请参阅https://www.javatpoint.com/command-line-argument

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM