Program to access numbers from the command line, sum, if the access is a string of solutions
Design ideas:
First define a double type of a one-dimensional array, and then define a double variable sum, and assign a value of 0, with the IF loop to determine if there is a parameter input from the command line, if not the output command line without parameter input, end the program, if there is, The string is converted to a double type with a For loop, and the output is summed with sum
Process The sequence flowchart is:
The program source code is:
Package demo;
Import Java.util.Scanner;
public class Arguments {
public static void Main (string[] args) {
TODO auto-generated method stubs
Double []a=new double[20];
Double sum=0;
if (args.length==0)//No arguments are entered into the command line
SYSTEM.OUT.PRINTLN ("command line without parameter input");
Else
{
for (int i=0;i<args.length;i++)//input parameters to the command line
{
A[i]=double.parsedouble (Args[i]); Convert to double type
Sum=sum+a[i];
}
System.out.println ("Sum of:" +sum); Output sum
}
}
}
The program is:
Java programming: string to numeric summation