package exercises.july30;

import java.util.ArrayList;
import java.util.List;

/**
 * Write a program to read a list of integer values which will find and display the
 * index of the first and last occurrence of the number 12. Your program should print
 * the index values -1 if the number 12 is not found.
 *
 * Yes, the exercise was /actually/ worded like this. Fml.
 */
public class ExerciseTwo {

    public static void main(String[] args) {
        // Diamond types are awesome. They let us create a container of explicit type without actually
        // specifying the needed type, as it can be inferred from the declaration.
        // This was introduced in Java 7.

        // An example of this is the call to new ArrayList<>(); below.

        // I'd usually use Long but the question specified integers
        List<Integer> integerss = new ArrayList<>();

        if (args.length < 1) {
            System.out.println("Please provide some numbers as arguments.");
            return;
        }

        for (String element : args) {
            int input;
            try {
                input = Integer.parseInt(element);
            } catch (java.lang.NumberFormatException e) {
                System.out.println("Unknown number: '" + element + "' - skipping..");
                continue;
            }
            integerss.add(input);
        }

        Integer first = -1;
        Integer last = -1;

        for (int i = 0; i < integerss.size(); i += 1) {
            if (first.equals(-1)) {
                if (integerss.get(i).equals(12)) {
                    first = i;
                }
            } else {
                if (integerss.get(i).equals(12)) {
                    last = i;
                }
            }
        }

        System.out.println("First index: " + first);
        System.out.println("Last index: " + last);
    }
}

@@ -1582,32 +1582,62 @@
      first = i;%0A
+                    last = i;%0A
                 
@@ -1630,32 +1630,32 @@
               %7D%0A
-
             %7D el
@@ -1775,32 +1775,145 @@
    %7D%0A        %7D%0A%0A
+        if (first.equals(last)) %7B%0A            System.out.println(%22Both indexes: %22 + first);%0A        %7D else %7B%0A    
         System.o
@@ -1941,32 +1941,36 @@
 ex: %22 + first);%0A
+    
         System.o
@@ -2000,20 +2000,30 @@
  %22 + last);%0A
+        %7D%0A
     %7D%0A%7D%0A

Improve exercise two slightly