Imitate the Javaapparguments.java example, write a program that receives multiple numbers from the command line, and then outputs the result after summing.

Source: Internet
Author: User

[Course Assignment 01]

    1. Design ideas

Using args[] Character array, the user in the parameter table in order to enter the parameters to add, the program statistics user input parameters, output parameters, sum assigned initial value is 0, the parameters are added to sum, the final output sum value.

Note: The parameters entered by the user are string types, which are converted to a double type and then added.

2. Program Flowchart

3. SOURCE program code

Public class ADD {

Public Static void Main (string[] args) {

double sum=0; Initialized and is 0

System. out. println ("Number of parameters:" +args.length);

for (String Arg:args)

{

System. out. println (ARG);//output user input parameters in turn

Sum=sum+double. parsedouble (arg);//Add parameters in turn

}

System. out. println ("sum=" +sum);//Output and

}

}

4. Results

Imitate the Javaapparguments.java example, write a program that receives multiple numbers from the command line, and then outputs the result after summing.

Related Article

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.