[Solved] JAVA: I have to write a program to read “sentences” from a file and and then count the number of words and vowels per sentence [closed]

Couple of issues: You are using last user entered sentence while you should use text that you read from file like below: StringTokenizer words = new StringTokenizer(text); numberofwords=numberofwords+words.countTokens(); for (i=0;i<text.length();i++) { ch=text.charAt(i); if (ch==’a’||ch == ‘A’ || ch == ‘e’ || ch == ‘E’ || ch == ‘i’ || ch == ‘I’ || ch == … Read more

[Solved] How to store each word from a scanner to an array

If I understand your question correctly, this is that I would do Scanner keyb = new Scanner(System.in); System.out.print(“Enter a sentence: “); String input = keyb.nextLine(); String[] stringArray = input.split(“,”); To see the results: for(int i=0; i < stringArray.length; i++){ System.out.println(i + “: ” + stringArray[i]); } This will work for any size sentence as long … Read more