Primes.java
1    // Program that uses one array to make another, swapping the first and last elements
2    
3    
4    
5    
6    package arrayplay;
7    
8    public class Primes {
9    
10       public static void main(String[] args) {
11   
12           int[] primes = new int[4];
13   
14           primes[0] = 2;
15           primes[1] = 3;
16           primes[2] = 5;
17           primes[3] = 7;
18   
19           System.out.println("Length of primes array = " + primes.length);
20           System.out.println("First prime = " + primes[0]);
21           System.out.println("Last prime = " + primes[3]);
22           System.out.println("Last prime = " + primes[primes.length - 1]);
23   
24           System.out.println("\nThe initial array ...");
25           int i = 0;
26           while (i < primes.length) {
27               System.out.println(primes[i]);
28               i = i + 1;
29           }
30   
31           int temp = primes[0];
32           primes[0] = primes[primes.length - 1];
33           primes[primes.length - 1] = temp;
34   
35           System.out.println("\nThe final array ... ");
36           for (int x = 0; x < primes.length; x = x + 1) {
37               System.out.println(primes[x]);
38           }
39       }
40   
41   }
42