Skip to content

Commit

Permalink
feat(7.4): finish unit 7 lesson 4 activities
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Jan 8, 2024
1 parent 607a871 commit e7ec3e4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/Unit7/U7_L4_Activity_One.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Unit7;

// Have to get rid of package statement

import java.util.ArrayList;

public class U7_L4_Activity_One {
public static int countSecondInitial(ArrayList<String> list, String letter) {
int count = 0;
letter = letter.toLowerCase();

for (String word : list) {
if (word.substring(1, 2).toLowerCase().equals(letter)) {
count++;
}
}

return count;

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

// Have to get rid of package statement

import java.util.ArrayList;

public class U7_L4_Activity_Two {
public static int searchSecond(ArrayList<String> list, String target) {
int count = 0;

for (int i = 0; i < list.size(); i++) {
if (list.get(i).equals(target)) {
if (count == 0) {
count++;
} else if (count == 1) {
return i;
}
}
}

return -1;
}
}

0 comments on commit e7ec3e4

Please sign in to comment.