1 package arrays; 2 //Working with the arrays of primes. 3 public class Primes { 4 public static void main(String[] args) { 5 int[] primes = new int[4]; 6 primes[0] = 2; 7 primes[1] = 3; 8 primes[2] = 5; 9 primes[3] = 7; 10 //gives me the highest length of the primes array. 11 System.out.println("length of primes = " + primes.length); 12 //gives me the first variable in the primes array. 13 System.out.println("first prime = " + primes[0]); 14 //gives me the last prime of the primes array using the last known number. 15 System.out.println("last prime = " + primes[3]); 16 //calculates last known number in primes array, using primes array length - 1. 17 System.out.println("last prime = " + primes[primes.length-1]); 18 System.out.println("\nThe initial array ..."); 19 int i = 0; 20 while (i < primes.length) { 21 System.out.println(primes[i]); 22 i = i + 1; 23 } 24 //this seems to flip the array. not completely sure how. 25 int temp = primes[0]; 26 primes[0] = primes[primes.length-1]; 27 primes[primes.length-1] = temp; 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