Skip to content

Commit

Permalink
Merge pull request #11 from 101zh/unit4.4
Browse files Browse the repository at this point in the history
Unit4.4
  • Loading branch information
101zh authored Nov 1, 2023
2 parents 5192612 + 215aa64 commit 617f6d0
Show file tree
Hide file tree
Showing 3 changed files with 86 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();
}

}
25 changes: 25 additions & 0 deletions src/main/java/Unit4/U4_L4_Activity_Three.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package Unit4;

import java.util.Scanner;

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

String word1 = scanner.nextLine();
String word2 = scanner.nextLine();

if (word1.length() == word2.length()) {

for (int i = word1.length(); i > 0; i--) {
System.out.print(word2.substring(i - 1, i));
System.out.print(word1.substring(i - 1, i));
}

} else {
System.out.println("error");
}

scanner.close();
}
}
29 changes: 29 additions & 0 deletions src/main/java/Unit4/U4_L4_Activity_Two.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package Unit4;

import java.util.Scanner;

public class U4_L4_Activity_Two {

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

String string = scanner.nextLine().toLowerCase();

String newString = "";

for (int i = 0; i < string.length(); i++) {
String letter = string.substring(i, i + 1);
boolean isMostCommonLetter = letter.equals("e") ||
letter.equals("t") ||
letter.equals("a") ||
letter.equals("i") ||
letter.equals("o");
if(!isMostCommonLetter){
newString+=letter;
}
}

System.out.println(newString);
scanner.close();
}
}

0 comments on commit 617f6d0

Please sign in to comment.