8 数组

例子:

求double型数组中所有元素的和

package com.wys.java;

public class arraylistDemo {
    public static void main(String[] args) {
        int size = 5;
        double[] myList = new double[size];
        myList[0] = 0.1;
        myList[1] = 0.2;
        myList[2] = 0.3;
        myList[3] = 0.4;
        myList[4] = 0.5;

        //计算所有元素总和
        double sum =0.0;
        for(int i=0; i){
            sum+=myList[i];
        }
        System.out.println("sum is: "+sum);
    }
}

8 数组_第1张图片

你可能感兴趣的:(8 数组)