Page 2 of 2 FirstFirst 12
Results 11 to 18 of 18
  1. #11

    Default Re: How to clear buffer in Java?


    ok.but you could change the delimiter by:
    new Scanner(System.in).useDelimiter("\n");

  2. #12

    Default Re: How to clear buffer in Java?

    Quote Originally Posted by cold_fusion
    ok.but you could change the delimiter by:
    new Scanner(System.in).useDelimiter("\n");
    salamat kaayo bai! murag ok na ni.. :mrgreen:
    what does a 'delimiter' mean btw?

  3. #13

    Default Re: How to clear buffer in Java?

    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.

  4. #14

    Default Re: How to clear buffer in Java?

    Quote Originally Posted by cold_fusion
    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.

    Another example is StringTokenizer.

  5. #15

    Default Re: How to clear buffer in Java?

    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

  6. #16

    Default Re: How to clear buffer in Java?

    Print the prompt then loop your program endlessly until you got '\n' as input.

  7. #17

    Default Re: How to clear buffer in Java?

    Quote Originally Posted by cold_fusion
    Print the prompt then loop your program endlessly until you got '\n' as input.
    thanks.. hmm.. i'm doing this.
    Code:
    char enter = 'a';
    System.out.println("Press ENTER to continue. ");
    while(enter != '\n')
      enter = keyboard.next().charAt(0);
    but it's not working.. i'm obviously doing it wrong. hehehe.

  8. #18

    Default a suggestion

    Quote Originally Posted by ares623 View Post
    i have a problem with my Java program..
    i need to input 2 Strings and 1 char using a Scanner object named console..
    so i use
    Code:
    Scanner console = new Scanner(System.in);
    ...
    String First = console.nextLine();
    char Middle = console.next().charAt(0);
    String Last = console.nextLine();
    now, it works fine the first time, but when I want to input again, it skips First and asks for Middle right away (especially when First or Last has blank spaces).
    i read about clearing input buffers in C when I had a similar problem, but how do I do it in Java?
    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.

  9.    Advertisement

Page 2 of 2 FirstFirst 12

Similar Threads

 
  1. how to print jtextarea in java
    By jairoh_ in forum Programming
    Replies: 5
    Last Post: 10-05-2012, 11:38 PM
  2. Replies: 96
    Last Post: 12-14-2008, 07:55 PM
  3. How to cook proper in Hotdogs!!!
    By kyme in forum Food & Dining
    Replies: 34
    Last Post: 12-14-2006, 07:13 PM
  4. How to have acess in the Mature Discussions...
    By emokidstuff in forum Support Center
    Replies: 2
    Last Post: 06-15-2005, 01:07 PM
  5. How to change ROM in SAP 1(HTC Tanager)
    By shadowkenshin in forum Gizmos & Gadgets (Old)
    Replies: 0
    Last Post: 04-21-2005, 02:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top