public class SumArray |
{ |
public static void main (String[] args) |
{ // array declaration |
int a[ ] = new int[10]; |
int total=0; |
/* initialize a - note the use of array instance variable length */ |
for (int i = 0; i < a.length; i++) |
{ a[i] = i * 5; } |
/* sum the array */ |
for (int i = 0; i < a.length; i++) |
total += a[i]; |
System.out.println( "\n" + "The sum of the array is " + total + "\n"); |
} |
} |
Familiar C operators ++ and += |
String catenation |