Saturday, 11 February 2017

Java program to calculate sum of 10 numbers entered by the user through the command line arguments.

import java.util.Scanner;

public class sum1
{

public static void main(String []args)
{

Scanner obj=new Scanner(System.in);

int[] array=new int[10];

int sum=0;

for(int i=0;i<array.length;i++){

System.out.println("Enter the "+(i+1)+" number");

array[i]=obj.nextInt();

sum+=array[i];

}

System.out.println("The sum is:"+ sum);

}

}

No comments:

Post a Comment