Hi Java professionals,
I am trying to write a program and the name variable can only store letters,dotes and spaces. But whenever I enter a space, the program doesn't work. Please help, thanks in advance and the following is my code.
import java.util.Scanner; import java.util.*; public class Space { public static void main(String []args) { Scanner reader = new Scanner(System.in); String name,email; while(true) { System.out.print("Please enter your name:"); name = reader.next(); System.out.print("Please enter your email address:"); email =reader.next(); if(name.equals("Quit")) { System.out.println("Bye!"); break; } if(name.matches("[^A-Za-z]+$")) { System.out.println("The name is invalid."); } } } }