Course Assignments:
Imitate the Javaapparguments.java example, write a program that accepts multiple numbers from the command line, and then outputs the result after summing.
Design ideas:
First read the numbers from the command line, and then calculate the sum of each number. To find the results.
Flow chart:
Program Source code:
Import java.io.*;
public class Sum
{
public static void Main (string[] args) throws IOException
{
int x,i;//i is used to count
Double sum;
String str;
BufferedReader buf;
sum=0;
for (i=1;i<11;i++)
{
System.out.print (" Please enter the number of" +i+ " :");
Buf=new BufferedReader (New InputStreamReader (system.in));
Str=buf.readline ();
X=integer.parseint (str);// read several words
Sum=sum+x;
}
System.out.println (" and for:"+sum);// output and
}
}
Result screenshot:
Java program input 10 numbers and sum