About the argument list of the main function string[] AGRs

Source: Internet
Author: User

    1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.