Assignemnt #126
Code
/// Name: Ryan Volko
/// Period: 7
/// Program Name: Getting
/// File Name: Getting.java
/// Date Finished: 5/18/2016
import java.io.File;
import java.util.Scanner;
public class Getting {
public static void main(String[] args) throws Exception {
int fourLetter = 0;
int caps = 0;
String fn1 = "words.txt";
String fn2 = "Getting.java";
Scanner wordReader = new Scanner(new File(fn1));
while(wordReader.hasNext()) {
String w = wordReader.next();
if(w.length() == 4)
fourLetter++;
}
wordReader.close();
Scanner selfInput = new Scanner(new File(fn2));
while(selfInput.hasNext()) {
String token = selfInput.next();
if(Character.isUpperCase(token.charAt(0)))
caps++;
}
selfInput.close();
System.out.println( fourLetter + " four-letter words in " + fn1);
System.out.println( caps + " words start with capitals in " + fn2);
//Happy New year To many People
}
}
Picture of the output