1 /* 2 This program creates an array of the first four prime numbers, prints them, and reverses the order 3 of the first and last element in the array then prints that 4 */ 5 6 7 8 package arrayPlay; 9 10 public class Primes { 11 12 public static void main (String [] args) { 13 14 int [] primes = new int[4]; 15 16 primes[0] = 2; 17 primes[1] = 3; 18 primes[2] = 5; 19 primes[3] = 7; 20 21 System.out.println("length of primes array = " + primes.length); 22 System.out.println("first prime = " + primes[0]); 23 System.out.println("last prime = " + primes[primes.length - 1]); 24 25 System.out.println("\nThe initial array..."); 26 int i = 0; 27 while (i < primes.length) { 28 System.out.println(primes[i]); 29 i = i + 1; 30 } 31 32 int temp = primes[0]; 33 primes[0] = primes[primes.length - 1]; 34 primes[primes.length - 1] = temp; 35 36 System.out.println("\nThe final array..."); 37 for (int x = 0; x < primes.length; x = x + 1) { 38 System.out.println(primes[x]); 39 } 40 } 41 } 42