java-integer addition sum

Source: Internet
Author: User

I. Design ideas

1. Create the project sum, add the class sum under Package Add, and the function is the sum of the integers.

2. Enter multiple integers.

3. Convert the input string to a number, import the package java.util with the import statement, and then call the class scanner

4. For sum initialization, add sums to multiple integers.

5. Outputs the sum result of multiple integers.

Two. Flowchart

Three. Source code

Package Add;

Import Java.util.Scanner;

public class Sum {

public static void Main (string[] args) {

String s;

Scanner sc=new Scanner (system.in);

SYSTEM.OUT.PRINTLN ("Please input three integers:\n");

int sum=0; Sum initialization

for (int i=0;i<3;i++) {

S=sc.next ();

int Parameter=integer.parseint (s); Convert a parameter in a string to an integer type

Sum+=parameter; Summation sum for each number of inputs

}

System.out.println ("The sum is:" +sum);

}

}

Four. Results

java-integer addition sum

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.