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; }}
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.