
11.10 Exercises,Problems,and Projects 803
EXERCISES,PROBLEMS, AND PROJECTS
while ( file.hasNext( ) )
{
String s = file.nextLine();
if ( s.equals( ”A“ ))
System.out.println( ”Excellent“ );
else if ( s.equals( ”B“ ))
System.out.println( ”Good“ );
else
System.out.println( ”Try to do better“ );
}
file.close();
}
catch ( IOException ioe )
{
ioe.printStackTrace();
}
19. What is the output of this code sequence?
try
{
Scanner file = new Scanner( new File( “data.txt” ));
String s = ” “;
while ( file.hasNext( ) )
{
s = file.nextLine();
}
if ( s.equals( ”A“ ))
System.out.println( ”Nice finish“ );
file.close();
}
catch ( IOException ioe )
{
ioe.printStackTrace();
}
4963X_CH11_Anderson