I'm having trouble having the do-while loop successfully change the integer to the value inside the if statement. It will exit the loop correctly if I enter 'y' or 'n', but the value of the integer will stay at 0.
I'm using substrings to allow the user to enter something like "yes" or "YEs", even "Y3$ir" and still equate to a 'y' to java.
Code:
import java.util.Scanner;
public class aTaskforAll
{
public static void main (String [] args)
{
Scanner scan = new Scanner(System.in);
String readAll;
int readAllOption = 0;
do {
System.out.print("Do you want the words printed? (y/n) ");
readAll = scan.nextLine();
System.out.println(readAll.substring(0));
if ((readAll.substring(0) == "y") || (readAll.substring(0) == "Y"))
readAllOption = 1;
else if ((readAll.substring(0) == "n") || (readAll.substring(0) == "N"))
readAllOption = 2;
}
while (readAllOption != 0);
System.out.println(readAllOption); //Tester
//Go on to do task in response to readAllOption = 1 or 2
}
}