ok.but you could change the delimiter by:
new Scanner(System.in).useDelimiter("\n");
ok.but you could change the delimiter by:
new Scanner(System.in).useDelimiter("\n");
salamat kaayo bai! murag ok na ni.. :mrgreen:Originally Posted by cold_fusion
what does a 'delimiter' mean btw?
you're welcome
Delimiter is the string that signals/defines the end or limit of something.
In your case "\n" or carriage return will delimit your Scanner object variables.
Sakto.Originally Posted by cold_fusion
Another example is StringTokenizer.
another question..
how do I make a prompt like this:
"Press ENTER to continue."
<user presses ENTER then the program continues>
sorry if this isn't allowed in here
Print the prompt then loop your program endlessly until you got '\n' as input.
thanks.. hmm.. i'm doing this.Originally Posted by cold_fusion
but it's not working.. i'm obviously doing it wrong. hehehe.Code:char enter = 'a'; System.out.println("Press ENTER to continue. "); while(enter != '\n') enter = keyboard.next().charAt(0);
Maybe you should try taking the entire line into a variable, and then finding out what your values are. It looks like when you get the first name, you use console.nextLine(), which would take the entire line, putting the entire name into the firstname variable.
and to answer your question, to clear the buffer you type
console.nextLine();
don't assign it to a variable and the input is just thrown out.
Last edited by c00ld1ds; 09-22-2009 at 11:23 AM.
Similar Threads |
|