I reccently got some homework which has me doing this weird task. The teacher wants us to split various sentences into words. The teacher has put these in a file which was imported through the scanner.
The teacher wants us to then with these words, to count the length, the number of words should increase with each iteration of the loop along with the number of words.
The file always ends with the character "#" so that is where i begun.
Here is what i have so far
class Assignmentfive
{
private static final String String = null;
public static void main(String[] args) throws FileNotFoundException
{
Scanner scan = new Scanner(new File("asgn5data.txt"));
String fileRead = " ";
System.out.print(fileRead);
double educationLevel = 0;
double wordCount = 0;
while (fileRead != "#")
{
fileRead = scan.nextLine();
int firstIndex = fileRead.indexOf(" ");
String strA = fileRead.substring(0,firstIndex);
System.out.print(strA);
int strLength = strA.length();
wordCount++;
}
Now, There is more at the bottom, that is my calculations, I cannot figure out how to extract word for word from the file
Any tips?
Thanks``