Count - } catch(IOException e) {...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.lang.String; import java.util.*; /** * @author * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class Count { public static void main(String Args[]) { BufferedReader file = null; String line = null; String fileName = "temp.txt"; try { file = new BufferedReader(new FileReader(fileName)); line = file.readLine(); } catch (FileNotFoundException e) { System.out.println("File: " + fileName + " not found.");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } catch(IOException e) { System.out.println("Error reading data from file: " + fileName); } //ArrayList names = new ArrayList(); HashMap names = new HashMap(); String name = null; S name = line.split(";"); int count = 0; i //System.out.println(name[5]); // convert array into hashmap (using // keys to remove duplicates) for (int x = 0; x < name.length ; x++) { if(names.put(name , " ")!= null) count++; } // print count System.out.println(names.size()); System.out.println(count); } }...
View Full Document

Ask a homework question - tutors are online