Main function parameter ARGs []

Source: Internet
Author: User

ARGs is an array that refers to the parameters passed in from the command line during running.

For example, compile a Java file: javac target. run Java again: Java target arg1 arg2. in the main method of the Java file, the input values can be obtained through two parameters: ARGs [0] And ARGs [1.

In eclipse, set arg1 arg2 in run/run independent variable/program independent variable and then use the dynamic line mode/Java application

Public class averagevalue {public static void main (string [] ARGs) {float [] temps = new float [10]; float sum = 0; int COUNT = 0; int I; int L = args. length; for (I = 0; I <args. length & I <10; I ++) {try {temps [I] = float. parsefloat (ARGs [I]); count ++;} catch (numberformatexception NFE) {system. out. println (ARGs [I]);} sum + = temps [I];} system. out. println (sum/I );}}

 

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.