alexi idreos
arraylist problems?
0 Answer(s)      5 years and a month ago
Posted in : Java Beginners

myprogram needs to ask the user for a file name. The file will contain a name on each line. Put each of the names into an ArrayList.

After you have put all of the names into the ArrayList search through the list and print out the following information;

Print out the longest name
Print out the shortest name
print out the total number of characters in all of the names.
print out the average number of characters per name
print out the whole list after the previous four pieces of information.

i have this so far. help with at least one aspect?

import; import; import; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Scanner;

public class project1 {

    public static void main(String[] args) throws IOException

          String filename = "";
          String longestString ="";
          int i;

          ArrayList<String> filestrings = new ArrayList<String>();

          Scanner keyboard = new Scanner(;

          System.out.print("Enter the name of the file you would like to search:");
          filename = keyboard.nextLine();

          File file = new File(filename);

          if (!file.exists())
          System.out.println("The file " +filename+ " is not found.");


          File file1 = new File(filename);
          Scanner inputFile = new Scanner(file);

          while (inputFile.hasNext())

          String line = inputFile.nextLine();
          System.out.println("There are " + filestrings.size() + " words in this document.");



View Answers