1 | public class SumArray |
2 | { |
3 | public static void main (String[] args) |
4 | { // array declaration |
5 | int a[ ] = new int[10]; |
6 | int total=0; |
7 | /* initialize a - note the use of array instance variable length */ |
8 | for (int i = 0; i < a.length; i++) |
9 | { a[i] = i * 5; } |
10 | /* sum the array */ |
11 | for (int i = 0; i < a.length; i++) |
12 | total += a[i]; |
13 | System.out.println( "\n" + "The sum of the array is " + total + "\n"); |
14 | } |
15 | } |
16 | Familiar C operators ++ and += |
17 | String catenation |