Consider the following code: scanner inputstream = null; try {inputstream = new
ID: 3799178 • Letter: C
Question
Consider the following code: scanner inputstream = null; try {inputstream = new scanner(new FileInputstream ("data.txt"));} catch(FileNotFoundException e) {system out.println("Error opening files"); system.exit(e);} while (inputstream.hasNextline()) {string aline = null; aline = inputstream.nextLine();} system.out.println(aline +^-^- + aline); and the following contents of data.txt: double toil trouble What does the program output? double double toil toil trouble trouble trouble trouble double toil trouble trouble trouble An error occursExplanation / Answer
Answer:
As per the code, program will not compile first. Becuase System.out.println(aLine + " "+aLine);
this statemnt is trying to print "aLine" String object value after while loop. But this object aLine declared in while loop so this aLine object will not be visible to outside of the while loop.
So here i am assumming that this statement System.out.println(aLine + " "+aLine); is in while loop.
if it is in while loop, then it will print below output
double double
toil toil
trouble trouble
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.