Basic HTML version of Foils prepared July 6 99

Foil 27 Example of basic language syntax

From Use of Java Language in Computational Science DoD Modernization Users Group Conference Monterey -- June 7 99. by Nancy McCracken, Geoffrey C. Fox


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

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Tue Jul 6 1999