Finding the Last 10 Elements in a Array
<p>Hey guys so I have to find the last 10 elements in my array in my <code>.txt</code> file filled with unsorted primes. The problem I'm having is the code I'm using to get the last 10 elements is just returning the same number instead of the last ten digits. If anyone can help me figure it out that would be great.</p>

<p>Also i have looked through some other code to figure it out, but i had no luck. If you do answer please don't just answer with a link to someone else code. Thanks</p>

<p>Heres my code so far:</p>

<pre><code>public class BubbleSort {

static long BubbleSortCount = 0;

public static void main(String[] args) throws IOException {

    System.out.print("This program compares the bubble, selection, merge sorts.\n"
            + "The data set is 78498 unsorted integers (prime numbers less than 1,000,000)\n\n");

    File file = new File("primes1.txt");

    Scanner infile = new Scanner(file);

    ArrayList&lt;Integer&gt; Primes1 = new ArrayList&lt;Integer&gt;();

    int temp;

    long startTime, endTime;

    int n;

    while (infile.hasNextInt()) {

        n = infile.nextInt();

        Primes1.add(n);

    }

    // bubble
    System.out.print("BUBBLE SORT\n");

    System.out.println("\nPrimes Read : " + Primes1.size());

    startTime = System.currentTimeMillis();

    Primes1 = Bubble(Primes1);

    endTime = System.currentTimeMillis();

    System.out.println("Elapsed Seconds = "

            + (double) ((endTime - startTime) / 1000.0));

    System.out.println("iterations = " + BubbleSortCount++);

    System.out.print("First 10 sorted : ");

    for (int i = 0; i &lt; 10; i++) {

        System.out.print(Primes1.get(i) + " ");
    }
    System.out.println();

    System.out.print("Last 10 sorted : ");

    for (int i = 0; i &lt; 10; i++) {

        System.out.print(Primes1.get(Primes1.size() - 1) + " ");
    }

}

// Bubble sort Method

public static ArrayList&lt;Integer&gt; Bubble(ArrayList&lt;Integer&gt; Primes1) {

    int temp;

    for (int i = 0; i &lt; Primes1.size() - 1; i++) {

        for (int j = 0; j &lt; Primes1.size() - 1; j++) {
            BubbleSortCount++;

            if (Primes1.get(j) &gt; Primes1.get(j + 1)) {

                temp = Primes1.get(j);

                Primes1.set(j, Primes1.get(j + 1));

                Primes1.set(j + 1, temp);

            }

        }

    }

    return Primes1;

}
}
</code></pre>

<p>Here are the numbers in my .txt file.</p>

<blockquote>
  <p>7
  2
  47
  13
  11
  59
  17
  41
  37
  23
  29
  31
  19
  53
  43
  241
  251 
  257 
  263 
  269 
  271 
  277 
  281 
  283
  293</p>
</blockquote>