8000 Feature: Implemented the logic for finding first uppercase instance o… · syedumerahmedcode/recursion@29193c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 29193c0

Browse files
Feature: Implemented the logic for finding first uppercase instance of an alphabet in the given string.
1 parent 8518596 commit 29193c0

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed
Binary file not shown.

bin/com/umer/main/Execute.class

495 Bytes
Binary file not shown.

src/com/umer/finduppercase/FindUppercaseService.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
public class FindUppercaseService {
44

55
public char findFirstUppercaseLetter(String inputForCheckingUppercaseLetter) {
6-
return ' ';
6+
// Exit condition
7+
if (inputForCheckingUppercaseLetter.isEmpty()) {
8+
return ' ';
9+
}
10+
// recursive flow
11+
if (Character.isUpperCase(inputForCheckingUppercaseLetter.charAt(0))) {
12+
return inputForCheckingUppercaseLetter.charAt(0);
13+
} else {
14+
return findFirstUppercaseLetter(
15+
inputForCheckingUppercaseLetter.substring(1, inputForCheckingUppercaseLetter.length()));
16+
}
717
}
818
}

src/com/umer/main/Execute.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ public static void main(String[] args) {
9393
System.out.println(findUppercaseService.findFirstUppercaseLetter(inputForCheckingUppercaseLetter));
9494
System.out.println();
9595

96+
inputForCheckingUppercaseLetter = "foobar";
97+
System.out.println(
98+
"Finding the first uppercase letter in the given input string: " + inputForCheckingUppercaseLetter);
99+
System.out.println(findUppercaseService.findFirstUppercaseLetter(inputForCheckingUppercaseLetter));
100+
System.out.println();
101+
96102
}
97103

98104
}

0 commit comments

Comments
 (0)
0