This is my first time posting on here, so if it is formatted poorly I apologize. My application is meant to ask the user to enter one of my roomates name, and the application will output information about that roomate. Then, it should ask the user if it wants to continue. I want it to only be able to accept 'y' or 'n'. When it asks if I want to continue, I enter a letter other than 'y' or 'n' and it correctly asks me to enter an acceptable answer. However, if I DO enter 'y' or 'n' it acts as if I entered an unacceptable answer ONLY ONE TIME, and THEN does what it is supposed to do. Any help is very appreciated.
package roomateapp;
import java.util.Scanner;
public class RoomateApp {
public static void main(String[] args) {
//Initialize scanner to take in roomate name
Scanner sc = new Scanner(System.in);
String cont = "y";
while (cont.equalsIgnoreCase("y")) {
//CODE HERE BUT NOT SHOWN
//Ask to continue
System.out.println("Would you like to continue? (y/n)");
cont = sc.next();
System.out.println();
if (!cont.equalsIgnoreCase("y") || !cont.equalsIgnoreCase("n")) {
while (!cont.equalsIgnoreCase("y") || !cont.equalsIgnoreCase("n")) {
System.out.println("Please enter 'y' or 'n'");
System.out.println("Would you like to continue? (y/n)");
cont = sc.next();
if (cont.equalsIgnoreCase("y") || cont.equalsIgnoreCase("n")) {
break;
}
}
} else {
}
System.out.println();
}
}
}