Write a program that receives multiple numbers from the command line and then outputs the results after summing.
(1) Design idea: Create a Class object--self-defined number of added numbers n--> input n numbers--loop add results
(2) Program Flowchart:
(3) Source program code:
Import Java.util.Scanner;
public class Test {
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner scan = new Scanner (system.in); Creating a Scanner Class object
int n;
System.out.println ("Please enter a few numbers to sum:");
n = scan.nextint ();//Enter the number of required and number
Double[] Adoubletarray;
Adoubletarray = new double[n];//defines n double-precision parameters
System.out.print ("Please enter" +n);
System.out.println ("A number:");
for (int i = 0; i<adoubletarray.length; i++)
{
Adoubletarray[i] = Scan.nextint ();//Enter n sum number
}//converts the input string into a floating-point type
Double result = 0;
for (int i = 0; i<adoubletarray.length; i++)
{
Result + = Adoubletarray[i];
}
SYSTEM.OUT.PRINTLN ("Add Result:" + result);//calculate and output the result
}
}
(4) Results:
Course Assignments 01