1 /* 2 * Program that works with an array of single digit primes. 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 int temp = primes[0]; 29 primes[0] = primes[primes.length-1]; 30 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