Requirements: Write a program that accepts multiple numbers from the command line, and then outputs the results after summing.
Design idea: Command line parameters are strings, you need to define an array to convert it to an integer, and then implement the number of the sum, and finally output the result.
Program Flowchart:
Program code:
Import Java.utill.Scanner;
public class javaapparguments{
public static void Main (string[] args) {
Scanner scan=new Scanner (system.in);//Create Scanner Class object
int n;
System.out.println ("Please enter the number of numbers required and:");
N=SCAN.NEXTLNT ();//requirements and number of numbers
Int[]array;
Array=new int[n];//defines n shaping parameters
System.out.pritln ("Please enter" +n+ "number")
for (int i=0;i<array.length;i++)
{
ARRAY[I]=SCAN.NEXTLNT ();//input N number
}//the input string into an integer
int num=0;
for (int i=0;i<array.length;i++)
{
Num+=array[i];
}//summation
System.out.println ("and for:" +num);//summation result
}
}
Program:
Results:
Imitation Javaapparguments.java Example