File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Study Material for Scanner and Fromatter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Study Material for Scanner and Fromatter" Watch "Study Material for Scanner and Fromatter" New topic
Author

Study Material for Scanner and Fromatter

Sandeep Chhabra
Ranch Hand

Joined: Aug 28, 2005
Posts: 340
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


Regards<br />Sandy<br />[SCJP 5.0 - 75%]<br />[SCWCD 1.4 - 85%]<br />------------------<br />Tiger, Tiger burning bright,<br />Like a geek who works all night,<br />What new-fangled bit or byte,<br />Could ease the hacker's weary plight?
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
http://www.java2s.com/ExampleCode/Language-Basics/JavaFormatterCreateatableofsquaresandcubes.htm


See the links under the code for more examples.


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
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

Joined: Aug 28, 2005
Posts: 340
Thanks for the Help Mr. Marcus.
 
Consider Paul's rocket mass heater.
 
subject: Study Material for Scanner and Fromatter