• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Study Material for Scanner and Fromatter

 
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can anyone suggest some good study material for Scanner and Formatter classes. I have read Sybex Complete Java 2 Certification, But i think the material in this book regarding Scanner is not sufficient.

Thanx for your help
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.java2s.com/ExampleCode/Language-Basics/JavaFormatterCreateatableofsquaresandcubes.htm


See the links under the code for more examples.
 
Marcus Green
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is some words I have put together on the subject of the Scanner class...

Scanner
The Scanner class makes it easier to break up input into managable data. The API documentation give a rather odd example of using the word fish as a delimiter. I suspect that more commonly encountered delimters would be either a simple blank space or one of the characters used when exporting data such as a comma, or pipe symbol (|). To give a trivial example with the default white space delimiter.

If you run this code it will simply take three int values from the command line.
The following code is a little more interesting and is adapted from the example given in the API docs that uses a delimiter of �fish�

If you run this code with the command line

The output will be
Input: 1 , 2 ,
Delimiter: ,
1
2

However, the delimter will only match a single space character, what if you have a slightly irregular file that sometimes has more than one space between the numbers. The Scanner can use just about any standard regular expression, so you can use

Note that if you need to use any expression with regular expression meaning, e.g. The bar character sometimes used as a separator for data you will need to use the backslash character to �escape� it. Thus

Will parse the input and output only the numbers.
 
Sandeep Chhabra
Ranch Hand
Posts: 340
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the Help Mr. Marcus.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic