PackageAdd;ImportJava.util.Scanner; Public classNumberplus { Public Static voidMain (string[] args) {Scanner scan=NewScanner (system.in);intA; System.out.println ("Please enter a few numbers to sum"); a=scan.nextint ();//Enter the number of requirements and the number ofDouble[] Adoublearray;adoublearray=New Double[A]; System.out.println ("Please enter" +a+ "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 typeDoubleResult=0; for(inti=0;i<adoublearray.length;i++) {result+=adoublearray[i];} System.out.println ("The added result is" +result);//calculate and output results} }
Design idea: Get the number of inputs, and then convert the numbers to be added into floating-point to add, and finally output
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, The numbers in the array are added to the output using the loop structure.
Course Assignments 01