To find the sum of any number of integers entered as command line arguments
To find the sum of any number of integers entered as command line arguments.
Program:
import java.util.Scanner;
public class SumofNumbers
{
public static void main(String[] args)
{
int i,sum=0,n,a;
Scanner sc= new Scanner(System.in);
System.out.println("Enter number of integer to calculate:");
n=sc.nextInt();
for(i=0;i<n;i++)
{
System.out.println("Enter the number:");
a=sc.nextInt();
sum=sum+a;
}
System.out.println("The sum of number is: "+sum);
}
}
OutPut:
Enter number of integer to calculate:
4
Enter the number:
1
Enter the number:
2
Enter the number:
12
Enter the number:
19
The sum of number is: 34
Post a Comment