Find the Sum of all array element in java


public class NewMain {
public static void main(String[] args) {
        // TODO code application logic here
        int i;
        int sum=0;
        int[] array=new int[5];

        for(i=0;i<5;i++)
        {
            array[i]=i;
        }
        
        for(i=0;i<5;i++)
        {
           sum=sum+array[i];
        }
        System.out.println("Sum of All Array Element is:"+sum);
    }
}
Output
Sum of All Array Element is:10

Share this article on