PROGRAM TO FIND THE SUM OF ELEMENTS OF A GIVEN ARRAY

//PROGRAM TO FIND THE SUM OF ELEMENTS OF A GIVEN ARRAY
class sumArray
{
int a[ ]={3,6,9,35,11,12,13},s=0,i;
int sum( )
{
for(i=0;i<=6;i++)
{
s=s+a[i];
}
return s;
}
public static void main(String args[ ])
{
int a;
sumArray s1=new sumArray( );
a=s1.sum( );
System.out.println(“Elements of array are: 3,6,9,35,11,12,13″);
System.out.println(“Sum of array elements is: “+a);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *