The title describes what I am trying to do.
The code doesn't have any errors, but it doesn't output true/false at the right times. For example, for the input
5 1 2 3 4 5 done
the output will be false, which is incorrect because you can see that 5 appears at the end and in another location in the ArrayList. So yeah, I could use some help de-bugging and I appreciate the help!
import java.util.ArrayList;
import java.util.Scanner;
public class LastRunner {
public static void main (String[] args)
{
Scanner s = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<>();
System.out.println("Enter some numbers. When done, type \"done\"");
while (s.hasNextInt())
{
list.add(s.nextInt());
}
int size = list.size();
boolean lastChecker = false;
for(int i = 0; i < size-1; i++)
{
if (list.get(size-1) == list.get(i))
{
lastChecker = true;
}
}
System.out.println(lastChecker);
}
}