Skip to content

Instantly share code, notes, and snippets.

@provencher
Created April 28, 2014 01:03
Show Gist options
  • Select an option

  • Save provencher/11359369 to your computer and use it in GitHub Desktop.

Select an option

Save provencher/11359369 to your computer and use it in GitHub Desktop.
IO Stuff
import java.util.*;
import java.io.*;
public class Test {
public static void main (String[] args){
ArrayList<String> storage = new ArrayList<>();
int counter = 0;
HashSet<String> reverse = new HashSet<>();
Scanner wordIn = null;
PrintWriter wordOut = null;
try{
wordIn = new Scanner(new FileInputStream("input.txt"));
}catch(FileNotFoundException e){
System.err.println("Hey man! DAT FILE AINT HERE!");
}
while(wordIn.hasNextLine()){
String temp = wordIn.nextLine();
storage.add(temp);
reverse.add(new StringBuilder(temp).reverse().toString());
}
try {
wordOut = new PrintWriter(new FileOutputStream("output.txt"));
}catch(FileNotFoundException e){
System.err.println("Hey man! DAT FILE AINT HERE!");
}
System.out.println(storage);
System.out.println("There are "+countChar(storage, 'e', 'E')+" iterations of the letter a");
wordOut.println(reverse);
wordOut.close();
wordIn.close();
}
public static int countChar(ArrayList<String> list, char letterSmall, char letterBig){
int counter = 0;
Iterator<String> itr = list.iterator();
while (itr.hasNext()){
String temp = itr.next();
for(int i = 0; i<temp.length(); i++){
if (temp.charAt(i) == letterSmall || temp.charAt(i) == letterBig){
counter++;
}
}
}
return counter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment