Originally Posted by
Norm
Scanner methods are tricky. Some require something be entered and will skip over white space and the Enter key waiting for input.
Try different Scanner methods for reading the input. Perhaps nextLine() will work better.
I won't swear on it but I'm quite sure I went through all of the scanner and string commands yesterday to find something that would work and accept space or enter as input. After hours of trying it didn't work out, I gave up and put it up here for help.....
Anyway,
import java.util.Scanner;
public class UserNames {
public static void main(String[] args0){
Scanner console = new Scanner(System.in);
String users = "";
String temp = "";
System.out.println("Type a person's name (or an empty line to stop): ");
temp = console.nextLine();
while(!temp.equals("")){
users += temp+" ";
System.out.println("Type a person's name (or an empty line to stop):");
temp = console.nextLine();
}
System.out.println("Welcome to all:"+users);
}
}
Thanks a lot, using nextLine() did the trick. I don't know what I did wrong yesterday for it not to work. It works perfect now.^^
I'm just surprised that it accepts as "Enter" as imput now when it wouldn't yesterday.
Thanks again for your help people, I shall jump into the depths of coding once again^^