I am attempting to create a program that counts the number of vowels in a sentence or text, which is inputted by the user.
PROBLEM: I am trying to use the length of the string to continue my loop until the very last character has been reached. However, the text.length only recognizes the first word and stops after spaces.
import java.util.*; public class Vowels{ public static void main(String[] args){ Scanner console = new Scanner(System.in); int counter= 0; System.out.println("Input a sequence of characters"); String text = console.next(); for (int loop = 0; loop < text.length(); loop++){ char lett = text.charAt(loop); if (lett=='a' || lett=='e' || lett=='i' || lett=='o' || lett=='u' || lett=='A' || lett=='E' || lett=='I' || lett=='O' || lett=='U') { counter++; } } System.out.println("There are " + counter + " vowels in the inputted text."); }