Hi,
I'm new to this forum and this is my first post so I hope I'm posting in the correct spot and that I am doing it correctly. I'm really new to programming but very keen to learn. Doing an IT degree. If anyone can tell me what I have done wrong here that would be great.
The program should count the amount of vowels that are in a string entered by the user.
import java.util.Scanner; public class VowelCounter { public static void main(String[] args) { Scanner input = new Scanner(System.in); char vowelCounter[] = new char[5]; vowelCounter[0] = 'a'; vowelCounter[1] = 'e'; vowelCounter[2] = 'i'; vowelCounter[3] = 'o'; vowelCounter[4] = 'u'; //Prompt user to input a string int counter = 0; String aString; System.out.println("Enter a string of text: "); aString = input.nextLine(); if (aString == "") { aString = input.nextLine(); } for (int i = 0; i < aString.length(); i++) { char charInPosition = aString.charAt(i); for (int j = i+1; j < vowelCounter.length; j++ ) { if (charInPosition == vowelCounter[j]) { counter++; } } } System.out.println(counter); } }