Java: Multiple Number summation

Source: Internet
Author: User

Design ideas:

Define an int n, define the number of inputs, enter a new dynamic array, enter a number into the dynamic array, function to convert and sum, and finally output.

Program Flowchart:

SOURCE program code:

Package com;

Import Java.util.Scanner;

public class Addadd {

public static void Main (string[] args) {

Scanner scan = new Scanner (system.in);// Create a Scanner class object

int n;

System.out.println (" Please enter the number of requirements and :");

n = scan.nextint ();// input requirements and number of

Double[] Adoubletarray;

Adoubletarray=new double[n];// defines n double-precision parameters

System.out.print (" Please enter " + N);

System.out.print (" a number :");

for (int i = 0;i < adoubletarray.length;i++)

{

Adoubletarray[i] =scan.nextint ();// Enter n sum number

}

Double add = 0;

for (int i=0;i < adoubletarray.length;i++)

{

Add +=adoubletarray[i];

}

System.out.println ("The result of all numbers added is :" +add); Calculate and Output

}

}

Java: Multiple Number summation

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.