Primes.java
1    /* 
2     *  Use the code provided for primes to learn how arrays function and some basic 
3     * characteristics/commands. 
4     */
5    
6    package arrayplay;
7    
8    public class Primes {
9    
10       public static void main(String[] args){
11           int[] primes = new int [4];
12            primes[0] = 2;
13            primes[1] = 3;
14            primes[2] = 5;
15            primes[3] = 7;
16   
17            System.out.println("length of primes array = " + primes.length);
18            System.out.println("first prime = " + primes.length);
19            System.out.println("last prime = " + primes[3]);
20            System.out.println("last prime = " + primes[primes.length-1]);
21   
22            System.out.println("\nThe intitial array ...");
23            int i = 0;
24            while (i < primes.length) {
25                System.out.println(primes[i]);
26                i = i + 1;
27            }
28   
29            int temp = primes[0];
30            primes[0] = primes[primes.length - 1] = temp;
31   
32            System.out.println("\nThe final array ...");
33            for ( int x = 0; x < primes.length; x = x+1){
34                System.out.println(primes[x]);
35            }
36       }
37   }
38