Skip to content

Commit c6ea0bd

Browse files
committed
Solution to Search Inside a String
1 parent b0c43ce commit c6ea0bd

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package LinearSearch;
2+
3+
public class SearchInRange {
4+
public static void main(String[] args) {
5+
6+
}
7+
8+
static boolean searchInRange(int startIndex, int endIndex, String name, char target){
9+
10+
if (name.length() == 0){
11+
return false;
12+
}
13+
for (int i = startIndex; i <= endIndex; i++){
14+
if (target == name.charAt(i)){
15+
return true;
16+
}
17+
}
18+
return false;
19+
}
20+
}

‎src/LinearSearch/SearchInStrings.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ public static void main(String[] args) {
88
System.out.println(searchInString(name,target));
99
}
1010

11+
static boolean searchInString2(String name, char target){
12+
13+
if (name.length() == 0){
14+
return false;
15+
}
16+
17+
for (char character: name.toCharArray()) {
18+
if (character == target){
19+
return true;
20+
}
21+
}
22+
return false;
23+
}
24+
1125
static boolean searchInString(String name, char target){
1226

1327
if (name.length() == 0){

0 commit comments

Comments
 (0)