Enter a few numbers at the command prompt, sum (flow chart I was sent in the form of a picture)

Source: Internet
Author: User

Program Design Ideas:

After visiting Baidu and other websites, I learned to convert the string s to an integer usable integer.parseint (s), so I knew how to translate the characters into integers. Enter multiple integers by a[i]=integer.parseint (Args[i]). Defines an array to receive numbers converted from characters, and finally sums them with a for loop.

Flow chart:

Program code:

public class add{

public static void Main (String args[]) {

int i,sum=0;

String c= "parameters are:";

String b= "sum is:";

Int[] A=new int[20];

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

System.out.println (c);

for (String Arg:args) {

System.out.println (ARG);

}

for (i=0;i<args.length;i++) {

A[i]=integer.parseint (Args[i]);

Sum=sum+a[i];

}

System.out.println (b+sum);

}

}

Program:

Enter a few numbers at the command prompt, sum (flow chart I was sent in the form of a picture)

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.