Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assuming the file words.txt holds the following data: CS1 Java Illuminated what

ID: 3772060 • Letter: A

Question

Assuming the file words.txt holds the following data:
CS1 Java Illuminated
what is the output of this code sequence:
a. If the file is found?
b. If the file is not found?

Try
{
Scanner file = new Scanner ( new File( “words.txt”));
String result = “”;
While ( file.hasNext())

{
String s = file.next();
Result += s;
Result+= “ And”;
}
System.out.println ( “result is “+result);
File.close();
}
Catch ( FileNotFoundExcption fne)
{
System.out.println( “Unable to find words.txt”);
}
Catch (I0Exception ioe)
{
Ioe.printStackTrace();
}

Explanation / Answer

if file words.txt is found the output is

CS1 And Java And Illuminated

if file is not found, error message is displayed
Unable to find words.txt

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote