Java: How do I add different paths in a application if the user inputs a certain phrase I needed them to say to create a different path in the app?

Hello fellow coders! So I’m creating a Java program, and I want to ask the user if they would like to continue doing the program. But all I know is how to create variables and print them. But for my code, my inputs that I need my user to put in is Y or N. Here’s the part I need help with:

System.out.println(“Insert Y to continue the program or N to stop the program.”);
Scanner scan = new Scanner(System.in);
String continueInput = scan.nextLine();

Though I have the users input, I need to know how to continue the program and run the rest of it for the user if they reply Y, or create a path that concludes the program for the user if they reply N.
So basically I need something that continues a path if Y or N is inputted.
Thanks for reading!

if this is all inside the main method, you could do something like:

if (continueInput.equals("Y")) {
  // rest of program here
}
else if (continueInput.equals("N")) {
  return;  // ends program if is inside main function
}

Look up conditionals in Java to learn more.
if-statements are used for this sort of thing.

Thanks! Just to confirm, both paths of code whether the user says N or Y is all written in one main method, in one class, right?

yes, you can have that in the main method.

I tried that, but “equals” was not recognized and only creates an issue with the program.

if (continueApp.equals(“N”)) {
// “equals” is not recognized and therefore cannot preform the action intended.

Hi @rauf321x, have you tried adding a conditional in the main method with the variable not being of type String but type boolean instead? Also, if you want different possible paths, have you tried using switch and having discreet blocks of code for each case? It may help keep your code shorter. I would recommend this guide from Codecademy on control flow. Lmk if that helps, I am happy to look at your code if you want to DM me. I hope this helps!