Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: java looping problem?

  1. #11
    Antionline Herpetologist
    Join Date
    Aug 2001
    Posts
    1,165
    hypronix, I've never seen the Scanner class before. Is it a new class added in Java 2 v5? I haven't yet explored it .

    Cheers,
    cgkanchi
    Buy the Snakes of India book, support research and education (sorry the website has been discontinued)
    My blog: http://biology000.blogspot.com

  2. #12
    Senior Member
    Join Date
    Jul 2003
    Posts
    813
    Originally posted here by cgkanchi
    hypronix, I've never seen the Scanner class before. Is it a new class added in Java 2 v5? I haven't yet explored it .

    Cheers,
    cgkanchi
    Yup! Wouldn't work on anything else, but if you tried that code [I did ] you'd see it runs smoothly... I haven't been exposed to any other form since I've just started out studying Java about a month ago [had the first midterm two days ago ]. But yeah, it was first released in 1.5 beta 1, used to get called as:

    Code:
    Scanner varName = Scanner.create(System.in);
    but in the stable version it gets called like so

    Code:
    Scanner varName = new Scanner (System.in);
    I s'ppose you could pass some other argument to it [not just System.in] but that's the only one I used so far.
    /\\

  3. #13
    Banned
    Join Date
    Sep 2004
    Posts
    305
    Originally posted here by cgkanchi
    ;TT :
    It should be buf.readLine() for String input. BufferedReader.read() only works for int's and char's.

    Phonedog911:
    Strange. I tried it out and get the same thing. Both are supposed to be equivalent. Looks interesting... I'll play a bit and get back to you.

    Cheers,
    cgkanchi
    Knew I'd make a mistake like that... I was taught input using the cs1.jar package so good eye.

  4. #14
    Senior Member
    Join Date
    Dec 2003
    Posts
    317
    thanx for the input, the teach has taught us to only use a buffered reader when you need to parse the input into an integer, we've been using system.in.read() for characters and he really should have said something if he wanted us to do it this way...

  5. #15
    Originally posted here by hypronix
    But yeah, it was first released in 1.5 beta 1, used to get called as:

    Code:
    Scanner varName = Scanner.create(System.in);
    but in the stable version it gets called like so

    Code:
    Scanner varName = new Scanner (System.in);
    You were correct in you assumption. Now you can scan from Files, String and Readables in addition to streams.
    As far as the visible change, from method call to constructor, they were using a factory to create them before, meaning that the one method (create()) did all of the hard work for you, my guess is that they changed it from an extendable or abstract class/interface into a final class and decided to make the constructors public because they can't be extended now, and besides a factory isn't necessary in a final class, because the purpose of a factory is to return an instance of the proper sub-class.

    If you would like to know more about factory patterns or any of the many other software design patterns and their many benefits check out some of these sites:
    http://www.dofactory.com/patterns/Patterns.aspx
    http://hillside.net/patterns/
    http://www.cs.wustl.edu/~schmidt/patterns.html
    and many, many more...
    --BigDick


    \"When in Rome, eat Rome!\" -Godzilla

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •