Skip to content

Commit

Permalink
feat(4.4.1): Finish U4_L4_Activity_One
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Nov 1, 2023
1 parent 5192612 commit abd3fbe
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/Unit4/U4_L4_Activity_One.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Unit4;

import java.util.Scanner;

public class U4_L4_Activity_One {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String string = scanner.nextLine().toLowerCase();
int pTimes = 0;

for (int i = 0; i < string.length(); i++) {
if (string.substring(i, i + 1).equals("p")) {
String nextLetter = string.substring(i + 1, i + 2);
boolean isVowel = nextLetter.equals("a") ||
nextLetter.equals("e") ||
nextLetter.equals("i") ||
nextLetter.equals("i") ||
nextLetter.equals("o") ||
nextLetter.equals("u");

if (isVowel) {
pTimes++;
}
}
}

System.out.println("Contains p followed by a vowel " + pTimes + " times.");
scanner.close();
}

}

0 comments on commit abd3fbe

Please sign in to comment.