I'm trying to write a loop that uses scanner to add integers to an established integer array list. It has to to be able to terminate the integer entries and proceed once "x" is entered, and prompt the user to re-enter an integer if any other letter is entered. My problem is that using .nextInt() I get run-time errors when entering a String. Am I simply using the wrong scanner method? This is what I have so far. I imported java.util.*
public static void main (String [] args)
{
Square square = new Square(); //constrcutor that establishes array list "square"
Scanner in = new Scanner(System.in);
int value = 0;
while (value != "x")
{
System.out.print("Enter an integer(x to exit): ");
value = in.nextInt();
if (in.nextInt() != "x" || value !> Integer.MIN_VALUE && value !< Integer.MAX_VALUE)
{
System.out.println("end");
System.exit(0);
}
square.add(value);
}
}