Create an array of 5 floats and calculate their sum in java .

 //Create an array of 5 floats and calculate their sum .

public class Nilesh {

    public static void main (String args[]){

       float addition=0;

        int i=0;

        // Creating an array sum

        // Declaration +Initialization + memory allocation attomatically.

        float [] sum ={1.2f , 2.15f, 5.1f, 8.3f, 9.2f};

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

                 addition=addition +sum[i];

        }

            // Printing addition using format specifier.

             System.out.printf("Addition of 5 float no. is =%f",addition);

       

Comments

Popular posts from this blog