Command-line arguments are strings, which must be converted to numbers before they can be added. The following is the flowchart, source code and output results.
Flow chart:
Source:
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
}
}
Results:
Java program--receives multiple numbers from the command line and outputs the result after summing