I'm trying to achieve something for a small personal bank account project that I'm practicing with. I want to make it so that if a user enters a space , or doesn't enter anything at all (meaning they pressed enter without entering a value) that the default name of the account switches to "Default".
Like so:
Scanner read = new Scanner(System.in);
System.out.print("Enter your account's name: ");
String input = read.next();
String name = "";
if (input == "" || input == null) {
name = "Default";
} else {
name = input;
}
Probably a stupid question, but this is one where I'm having a little trouble on. If I enter a space and then press enter, it doesn't continue to set the name. If I press enter when it prompts for an input, it doesn't continue to set the name. Is there a way to set it?
Edit: I don't want to know whether or not a String equals another string via .equals() (thank you for pointing that out, by the way). The scanner still does not accept blank inputs.