Skip to content

Commit

Permalink
fix(4): change Alg1 to initialize i at 0
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Nov 6, 2023
1 parent 66a101d commit c4f65e2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/main/java/Unit4/Assignment4.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ public static void main(String[] args) {

int vowelCount = 0;
int repeatCount = 0;
for (int i = 1; i < string.length(); i++) {
for (int i = 0; i < string.length(); i++) {
String letter = string.substring(i, i + 1);
String previousLetter = string.substring(i - 1, i);
boolean isVowel = letter.equals("a") ||
letter.equals("e") ||
letter.equals("i") ||
letter.equals("i") ||
letter.equals("o") ||
letter.equals("u");

if (!previousLetter.equals(" ") && isVowel)
if (i != 0 && !string.substring(i - 1, i).equals(" ") && isVowel)
vowelCount++;
else if (previousLetter.equals(letter))
else if (i != 0 && string.substring(i - 1, i).equals(letter))
repeatCount++;
else
alg1String += letter;
Expand Down

0 comments on commit c4f65e2

Please sign in to comment.