Sunday, August 12, 2012

Java program to find sum of the elements of an array


class arraysum
       {
int a[],sum;
arraysum()
    {
a= new int[12];
sum=0;
for(int i=0;i<12;i++)
    {
a[i]=i+1;
    }
  }
void add()
 {
for(int i=0;i<12;i++)
    {
sum=sum+a[i];
     }
System.out.println("\t"+"sum of elements of array is "+sum);
 }

void disp()
{
for(int i=0;i<12;i++)
{
System.out.println(i+" ");
}
}

public static void main(String s[])
 {
arraysum as = new arraysum();
as.disp();
as.add();
 }

       }

1 comments:

  1. tHIS YOUR CODE DOES NOT WORK, PLS, CHECK AND COME AGAIN

    ReplyDelete