Lecture 6 – January 27, 2005

 

Lab information

          see methods of Scanner class on page 90

myFileScanner = new Scanner (new File (  “input.txt”));  // simple filename

myFileScanner = new Scanner (new File (“C:\Temp\input.txt”)); // doesn’t work

myFileScanner = new Scanner (new File (“C:\\Temp\\input.txt”)); //  works

   \ is an escape character when reading a character at a time which is what

   happens here.

Mike F suggests using the forward slash instead of the back slash and it worked and didn’t need to be doubled.

Robert said that to avoid the compile error message “myFileScanner may not have been initialized” he just said myFileScanner = new Scanner (“dummyFile”); and it worked.  This fooled the compiler but may not work at runtime

Two additional things to think about

·        Which loop to use :  do … while   or   while

·        Should the for loop be in the try/catch block or should the ttry/catch block be in the for loop?

 

Quiz – had errors

          how graded

          give them template to correct  Quiz2b.java

          raises questions about data types

                    String

                    arrays

 Arrays

 

 

Review primitive types

 

Enumerated types

 

Iterators