[Course Assignment 01]
- Design ideas
Using args[] Character array, the user in the parameter table in order to enter the parameters to add, the program statistics user input parameters, output parameters, sum assigned initial value is 0, the parameters are added to sum, the final output sum value.
Note: The parameters entered by the user are string types, which are converted to a double type and then added.
2. Program Flowchart
3. SOURCE program code
Public class ADD {
Public Static void Main (string[] args) {
double sum=0; Initialized and is 0
System. out. println ("Number of parameters:" +args.length);
for (String Arg:args)
{
System. out. println (ARG);//output user input parameters in turn
Sum=sum+double. parsedouble (arg);//Add parameters in turn
}
System. out. println ("sum=" +sum);//Output and
}
}
4. Results
Imitate the Javaapparguments.java example, write a program that receives multiple numbers from the command line, and then outputs the result after summing.