As we all know, Java programs can receive parameters from the command line, and the following program demonstrates how to get command-line arguments:
The code is as follows:
* * Demo Main method receive string from console
*thinking in Java Test 2.10
* @author: Wolfofsiberian/Public
class Tij_ test2_10{public
static void Main (String args[]) {
//Determine whether the console passes in the parameter
if (0!= args.length) {for
(int i=0;i <args.length;i++) {
System.out.println ("args[" +i+ "]="));
}
else{
System.out.println ("Command line is empty!");}}
Execution Results:
(See from the execution result, when the command line passes in the parameter, use the space match to divide each parameter, and then save each parameter into a string array)
E:\Java se\thinking in Java>java tij_test2_10
Command line is empty!
E:\Java se\thinking in Java>java tij_test2_10 A B C D E
args[0]=a
args[1]=b
Args[2]=c
ARGS[3]=D
args[4]=e
E:\Java se\thinking in Java>java tij_test2_10 A B C D E aadfa afjad;fja;
Args[0]=a
args[1]= B
Args[2]=c
Args[3]=d
args[4]=e
Args[5]=aadfa
Args[6]=afjad;fja;