Results 1 to 2 of 2
  1. #1
    Xonian is offline Member
    Join Date
    May 2014
    Rep Power

    Default Need help with .next() method and tokens

    Hey guys. I just started learning Java a few days ago. Everything makes sense so far, but I have a few things I need cleared up. First off, can someone please give a simple explanation as to what a token is?

    Also, I have attached a simple program I made, from a tutorial, and I don't understand the purpose of the .nextDouble() method. In my program, I have the variable aavo set as my Scanner variable. My tenth line states fnum = aavo.nextDouble();. It is declaring the variable fnum equal to the Scanner variable, but what does the .nextDouble method do? And an explanation as to why I am able to declare the variable snum equal the same thing as the other double variable would be great.

    Thanks a lot guys!
    Attached Thumbnails Attached Thumbnails Need help with .next() method and tokens-applesscreen.png  

  2. #2
    kneitzel is offline Senior Member
    Join Date
    Feb 2014
    Rep Power

    Default Re: Need help with .next() method and tokens

    Did you read the documentation of the scanner class?
    Scanner (Java 2 Platform SE 5.0)

    Or maybe you had problems understanding the construct
    fnum = aavo.nextDouble();

    This is not assigning your scanner instance to fnum!
    The right side is evaluated first, so if you have something like:
    someInstance.someMethod(anotherInstance.something( )).anotherMethod()
    Then first anotherInstance.something() is called.
    Then someInstance.someMethod(lastResult) is called.
    Then lastResult2.anotherMethod() is called
    where lastResult and lastResult2 are the return values of the call before.

    So in your case, nextDouble is called on the scanner instance and the result is stored in fnum.

Similar Threads

  1. tokens from StringTokenizer
    By programcı in forum New To Java
    Replies: 1
    Last Post: 04-05-2011, 04:36 PM
  2. Looping through tokens
    By Landon in forum New To Java
    Replies: 1
    Last Post: 09-12-2010, 11:34 AM
  3. Indexing tokens
    By peliukasss in forum Lucene
    Replies: 4
    Last Post: 08-06-2010, 01:40 AM
  4. tokens
    By Gilgamesh in forum New To Java
    Replies: 5
    Last Post: 12-02-2007, 11:30 PM
  5. tokens
    By Gilgamesh in forum New To Java
    Replies: 3
    Last Post: 11-25-2007, 02:39 AM

Tags for this Thread

Posting Permissions

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