generated from microsoft/vscode-remote-try-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(7.4): finish unit 7 lesson 4 activities
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |