String[] args is specifically used to receive command-line arguments.
2. For example: Java ArrayTest07 abc def AAA JVM before invoking the main method of the ArrayTest07 class, the string "ABC def AAA" is separated by a "space" and stored in a string array.
The experiment code is as follows:
Public class maintest{ public static void main (String[] args) { system.out.println (" The number of elements in an array of type string is: " + args.length";//0 does not receive parameters, all are 0; / /traverse this array for (int i=0;i<args.length;i++) { System.out.println (Args[i]);} Design such a requirement: To run the software must increase the user name and password, user name:admin password: 123, if not provided sufficient parameters, the system exits; if the number of parameters is correct, the user name and password is correct, then prompt * * * Login successful, welcome back! "; User name or password error, also give the corresponding prompt. if (args.length != 2) { system.out.println ("To use this system you must enter this:username Password "); return ;} string username=args[0]; String passwd = args[2];if ("admin". Equals (username) && "123". Equals (passwd)) {//This is written in comparison to the following, You can avoid null pointer exception//if (username.equals ("admin") && passwd.equals ("123") SYSTEM.OUT.PRINTLN ("Login successful, welcome [" +username+ "] come back! ");} ELSE{&NBSP;&NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("Login failed, user name [" +username+ "] does not exist or the password is wrong! ");} }}
This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1661768
About the argument list of the main function string[] AGRs