Receive multiple numbers from the command line with the Java implementation and then output the result after summing

Source: Internet
Author: User

1. Design Ideas

The first thing to know is the meaning of entering numbers from the command line, which you don't need to define in your program. You need to define NUM and sum for the int class. After that, Num=integer.parseint (ARG) is used and the string type is converted to int type. The For loop is then used to add num to the sum in turn.

2. Program Flowchart

3. Source code


public class Word {
Letter 1603 20163535 Liu School speech
public static void Main (string[] args) {
TODO auto-generated method stubs
System.out.println ("Number of parameters" +args.length);
int num;
int sum=0;
for (int i=0;i<args.length;i++)//Loop
{
Num=integer.parseint (Args[i]);//cast string argument to int type
Sum=sum+num;
}
System.out.println ("Several numbers combined with" +sum);//Output
}

}

4. Running

Receive multiple numbers from the command line with the Java implementation and then output the result after summing

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.