Problem

Fix the ErrorsFind the errors in the following program and correct them so that the progra...

Fix the Errors

Find the errors in the following program and correct them so that the program does what it should do. There are both syntax errors and semantic (logical) errors.

class WeTryHarder{   // This program is supposed to read a text file  // and display a String composed of the first letter  // from each line of the file. For example, if the file was  // composed of the first three lines from the Reel Big Fish  // song Go Away :    // She was never what I wanted,    // I just wanted someone else.    // Now I’m sittin’ here alone,// The output would be "SIN".  void public main(String[] args)  {    File inputFile = new ("reelbigfish.txt");    if (!inputFile.exists())    {      System.out.println("File reelbigfish.txt not found");      System.exit(0);    }   Scanner input = Scanner(inputFile);   String firstLetters = new String(); // to hold the first letters of each line   String line; // to hold a line of input from the file   while (input.hasNext())   {     line = new String(input.nextLine()); // get next line     firstLetters = firstLetters + line.charAt(0); // concatenates the first                           // character of line to firstLetters   }   System.out.println(firstLetters);   inputFile.close;   }}

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 9
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT