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