Primes.java
1    /* 
2    * this program introduce us how to read the array and to print out the values of the elements 
3     */
4    
5    package arrayPlay;
6    
7    public class Primes {
8        public static void main(String[] args) {
9    
10           int[] primes = new int[4];
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           int temp = primes[0];
28           primes[0] = primes[primes.length - 1];
29           primes[primes.length - 1] = temp;
30   
31           System.out.println("\nThe final array...");
32           for (int x = 0; x < primes.length; x = x + 1) {
33               System.out.println(primes[x]);
34           }
35       }
36   }