Java Multiple number addition source code flowchart design Idea

Source: Internet
Author: User

First, design ideas:
1, understand the requirements of the topic, that is, to write a program to complete the addition of multiple numbers and output results, the problem is the command line parameter is a string, need to be converted into a number after the calculation, by querying the internet to solve the problem method, with "*.nextint ()" function can solve the issue.
2, the structure of the design program, the first to apply for dynamic space, to complete the requirements to enter multiple numbers. Finally, the program is completed by inputting, calculating and outputting.

Second, the Process flow chart

Third, the source code

Package Sum;import Java.util.Scanner; Public classText { Public Static voidMain (string[] args) {Scanner scan=NewScanner (System.inch);//creating a Scanner class object                intN; System. out. println ("Please enter a few numbers to sum:"); N= Scan.nextint ();//Enter the number of required and                Double[] numarray; Numarray=New Double[n];//define n variable of type doubleSystem. out. Print ("Please enter"+N); System. out. println ("a number to calculate:");  for(inti =0; i<numarray.length;i++) {Numarray[i]= Scan.nextint ();//Enter the n numbers to be computed}//converts the input string to a floating-point type                Doublesum =0;  for(inti =0; i<numarray.length;i++) {sum+=Numarray[i]; }//calculation of the number of inputs andSystem. out. println ("The and of these several numbers are:"+sum);//Output Calculation Results    }}

Iv. Results

Java Multiple number addition source code flowchart design Idea

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.