Hello all.
So my first assignment in my computer science class is to write a program that counts the number of vowels. Basically, runningshould returnjava main.Assignment1 "This is one argument" "A second one"
.Argument 1: 1 a, 2 e, 2 i, 1 o, 1 u Argument 2: 1 a, 2 e, 0 i, 2 o, 0 u All: 2 a, 4 e, 2 i, 3 o, 1 u
I'm very new Java. I have a working code, but it would only work for one argument:
package main; public class Assignment1 { public static void main(String args[]) { String str = args[0]; int numA = 0; int numE = 0; int numI = 0; int numO = 0; int numU = 0; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == 'A' || c == 'a') { numA++; } if (c == 'E' || c == 'e') { numE++; } if (c == 'I' || c == 'i') { numI++; } if (c == 'O' || c == 'o') { numO++; } if (c == 'U' || c == 'u') { numU++; } } System.out.print("Argument 1: "); System.out.print(numA + " a, "); System.out.print(numE + " e, "); System.out.print(numI + " i, "); System.out.print(numO + " o, "); System.out.print(numU + " u"); } }
My question is how can I make this work for any number of input arguments?