Design idea: Get the number of inputs, and then convert the numbers to be added into floating-point to add, and finally output
Source:
Package Add;
Import Java.util.Scanner;
Shi Yuqing 2015.9.26
public class Add {
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner scan = new Scanner (system.in);
int n;
System.out.println ("Please enter a few numbers to sum");
N=scan.nextint (); //Enter the number of requirements and number
Double[] Adoublearray;
Adoublearray =new double [n];
System.out.println ("Please enter" +n+ "number");
for (int i=0;i<adoublearray.length;i++)
{
Adoublearray[i]=scan.nextint (); //Enter n sum number
}//Convert the input string to a floating-point type
Double result=0;
for (int i=0;i<adoublearray.length;i++)
{
Result+=adoublearray[i];
}
SYSTEM.OUT.PRINTLN ("Add result is" +result); //calculate and output results
}
}
Program:
Java receives multiple numbers from the command line and outputs the results after summing