import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.FileReader; import java.util.ArrayList; import java.util.Scanner; // Report on characters that make up contents of text file (argument 1 [inputfile.txt]) public class FindOccurrences { // Case Insensitive letter issue public static String upLow(String incha, Boolean caseConcern) { if (!caseConcern && !incha.toLowerCase().equals(incha.toUpperCase())) { return incha.toLowerCase() + " or " + incha.toUpperCase(); } return incha; } // Return number of words within string public static int withinStringNumWord(String instrng, Integer wordChars) { Integer wcount = 0, ich, withinword=0; for (ich=0; ich 0) { if (withinword == 0) wcount++; withinword = 1; wordChars++; } else { withinword = 0; } } return wcount; } // Return number of occurrences of character within string public static int withinStringNumLetter(String instrng, String inchar) { Integer ccount = 0, ich; for (ich=0; ich oura, ArrayList ouri) throws IOException { try { String nonh = ""; BufferedReader ourreader = new BufferedReader(new FileReader(filenm)); String linerec = null; Integer numfrecs = 0, irec=0, j, thisk, numchar=0, other=0, wordcount=0, wChars=0; Boolean firstNumLook = true; while ((linerec = ourreader.readLine()) != null) { if (firstNumLook) { try { numfrecs = Integer.valueOf(linerec); nonh = " non-header"; } catch (Exception err) { firstNumLook = false; numfrecs = -1; } } if (!firstNumLook && numfrecs != 0) { numchar += linerec.length(); irec++; wordcount += withinStringNumWord(linerec, wChars); for (j=0; j ourLetter = new ArrayList(); // characters ArrayList ourLetterCount = new ArrayList(); // occurence Boolean caseWorry = false; String filnm = "inputfile.txt"; String spares = "Enter input filename"; String charOfInterest = "-+()':;?!=$.@#&%0123456789abcdefghijklmnopqrstuvwxyz "; String up, low; Integer ipos; Scanner input = new Scanner(System.in); // Check for argument 1 filename if (args.length > 0) { filnm = args[0]; } else { System.out.printf("%s [%s] ... prefix * for case sensitivity\n", spares, filnm); spares = input.nextLine(); if (spares.indexOf("*") >= 0) caseWorry = true; if (spares.replace("*", "").length() > 0) filnm = spares.replace("*", ""); } // Populate ArrayList for (ipos=0; ipos