Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. COHaven't seen the scanner one before...neat. But, what you have there fails if you pass "1 A" where the scanner word separation will give you multiple tokens. So, you would need to modify your above such that a Number 'n' is set on hasNextInt and hasNextDouble, skip the final else and then have a separate if statement to see if the scanner has any following tokens, ala n!=null && scanner.hasNext(). Both this and the ParsePosition allow leading and trailing whitespace - so that would still be one for op to deal with as appropriate but with these fixes I think you have a pretty good solution.
      singulars
    2. COThis answer would benefit from a mention of [`useLocale`](http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html#useLocale%28java.util.Locale%29), as well as philwb’s addition. Otherwise, top.
      singulars
    3. CO@KonradRudolph, `Scanner.useLocale` is already mentioned on the last line of the answer. As far as @philwb's suggestion is concerned, I think it really depends on possible constraints you may have on the input the program receives. For example, if the string is allowed to contain multiple tokens, and space is used to separate them, I think that trimming, splitting, then cycling on the resulting array with the snippet I provided would do. The OP doesn't mention anything about such constraints, just providing some example tokens, so I prefer not to steer my answer in one direction or another.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload