Design ideas: Get the number of inputs, and then convert the numbers to be added to float to add, and then output the results.
Flow chart:
1: Set up a scanner object scan;
2: Define a dynamic array adoublearray[];
3: Using the loop structure to input the number into the array;
4: Use the loop structure to add the numbers in the array to the output.
Source:
PackageNiuke;ImportJava.util.Scanner; Public classAdd { Public Static voidMain (string[] args) {Scanner scan=NewScanner (system.in); intN; System.out.println ("Please enter a few numbers to sum"); N=scan.nextint ();//Enter the number of requirements and the number of Double[] adoublearray; Adoublearray=New Double[n]; System.out.println ("Please enter" +n+ "number"); for(inti=0;i<adoublearray.length;i++) {Adoublearray[i]=scan.nextint ();//Enter a number of n sums }//converts the input string to a floating-point type DoubleResult=0; for(inti=0;i<adoublearray.length;i++) {result+=Adoublearray[i]; }system.out.println ("The added result is" +result);//calculate and output results}}
:
Java: Receives multiple numbers from the command line and outputs the result after summing