I've been messing around with this for a bit and cannot seem to code it so that it will work as intended. I'm trying to prompt the user for input repeatedly, until the user enters a -1, when the loop is supposed to terminate.
My problem lies in that the loop does not stop when -1 is entered. What am I doing wrong here?
import java.util.Scanner; class Test{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); String in = scan.nextLine(); while(in != "-1"){ System.out.println("You entered: " + in); in = scan.nextLine(); if(in == "-1") System.out.println("Stopped"); break; } } }