Primes.java
1    package arrayplay;
2    
3    public class Primes {
4        public static void main(String[] args) {
5            int[] primes = new int[4];
6    
7            primes[0] = 2;
8            primes[1] = 3;
9            primes[2] = 5;
10           primes[3] = 7;
11   
12           System.out.println("length of primes array = " + primes.length);
13           System.out.println("first prime = " + primes[0]);
14           System.out.println("last prime = " + primes[3]);
15           System.out.println("last prime = " + primes[primes.length - 1]);
16   
17           System.out.println("\nThe inital array ...");
18           int i = 0;
19           while (i < primes.length) {
20               System.out.println(primes[i]);
21               i = i + 1;
22           }
23   
24           int temp = primes[0];
25           primes[0] = primes[primes.length-1];
26           primes[primes.length-1] = temp;
27   
28           System.out.println("\nThe final array ...");
29           for (int x = 0; x < primes.length; x = x + 1 ){
30               System.out.println(primes[x]);
31           }
32       }
33   }
34