The Java implementation receives multiple numbers from the command line and outputs the results after summing.

Source: Internet
Author: User

The Java implementation receives multiple numbers from the command line and outputs the results after summing.

1 Design ideas:

(1) Create a class.

(2) The number of output parameters.

(3) defines the NUM and sum of int, which is used to store the sum of parameters and parameters respectively.

(4) A For loop argument is coerced into an int, and the converted parameter and sum are added, and the final result is recorded with Sum.

(5) Output sum.

2 Program Flowchart:

3 Source code:

Package CSXJ;
public class Csxj {
public static void Main (string[] args)
{
System.out.println ("Number of parameters" +args.length);
int num;//parameters that store integer types
int sum=0;//parameter's and
for (String Arg:args)//Loop
{
Num=integer.parseint (ARG);//cast string argument to int type
Sum=sum+num;
}
System.out.println ("Several numbers combined with" +sum);//Output

}
}

4 results:

Input parameters:

Operation Result:

The

receives multiple numbers from the command line with the Java implementation and outputs the results 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.