Java program to print the sum of all numbers in a given array
KW.java
class KW
{
    public static void main(String args[])
    {
        double sum=0;
        double []a={100,15,15.15,40,45.99};
        for(int i=0;i<a.length;i++)
        {
            sum=sum+a[i];
        }
        System.out.println("The addition of array is = "+sum);
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW The addition of array is = 216.14000000000001 kodingwindow@kw:~$
Advertisement