Java: Array with loop

后端 未结 9 1001
借酒劲吻你
借酒劲吻你 2020-12-06 04:49

I need to create an array with 100 numbers (1-100) and then calculate how much it all will be (1+2+3+4+..+100 = sum).

I don\'t want to enter these numbers into the a

9条回答
  •  有刺的猬
    2020-12-06 05:16

    int count = 100;
    int total = 0;
    int[] numbers = new int[count];
    for (int i=0; count>i; i++) {
        numbers[i] = i+1;
        total += i+1;
    }
    // done
    

提交回复
热议问题