bool keepGoing = True;
while (sc.nextLine() && keepGoing) {
String userInput = sc.next();
put your if statement here and set keepGoing to false when it matches "quit"
}
Scanner scan = new Scanner (System.in);
while (true) {
System.out.println ("Express yourself:");
String userInput = scan.nextline ();
if (userInput.equals ("quit")) break;
System.out.println (userInput);
}
System.out.println ("Goodbye!");
How can I make a program that takes in multiple lines of input and says it back, but quits the moment you input, "quit."
I have the following, but do not know how to make it quit or how to even let it run more than once
--------
import java.util.Scanner;
public class fracCalc {
public static void main(String[] args) {
Scanner fraccalc = new Scanner (System.in);
System.out.println("Express yourself:");
String userInput = fraccalc.nextLine();
if (userInput != "quit") {
System.out.println(userInput);
} else {
System.out.println("Goodbye!");
}
}
}