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

Write a main method similar to the one below, but with the following differences

ID: 3692790 • Letter: W

Question

Write a main method similar to the one below, but with the following differences. Inside the curly braces of the main method, delcare an array of references to String objets. You'll need Java code that looks something like this:

final int MAX = 100;

String [] lines = new String[MAX];

------------------------------------------------------------------------------------------------------

//displays the contents of the file quotations.txt. on the screen

import java.util.*;
import java.io.*;
public class File1
{
public static void main(String[] args) throws IOException
{
File inputFile = new File("quotations.txt.");
if (!inputFile.exists())
{
System.out.println("File quotations.txt not found.");
System.exit(0);
}
Scanner input = new Scanner(inputFile);
String line; // to hold one full line from the file
  
while (input.hasNext()) // while there is more data
{
line = input.nextLine(); //advance to next liine, returns all "skipped" data
System.out.println(line);
}
input.close();
}
}
  

Explanation / Answer

import java.util.*;
import java.io.*;
public class File1
{
public static void main(String[] args) throws IOException
{

final int MAX = 100;

String [] lines = new String[MAX];

File inputFile = new File("quotations.txt.");
if (!inputFile.exists())
{
System.out.println("File quotations.txt not found.");
System.exit(0);
}
Scanner input = new Scanner(inputFile);
       // to hold one full line from the file
int i=0;
while (input.hasNext()) // while there is more data
{
lines[i] = input.nextLine(); //advance to next liine, returns all "skipped" data
System.out.println(lines[i++]);
}
input.close();
}
}

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