Skip to content

Commit 7b6accc

Browse files
committed
letter Search program
1 parent d4a40fc commit 7b6accc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Diff for: .idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/Chapter4/LetterSearch.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package Chapter4;
2+
3+
import java.util.Scanner;
4+
5+
public class LetterSearch {
6+
public static void main(String[] args) {
7+
System.out.println("Please enter your text");
8+
Scanner scanner = new Scanner(System.in);
9+
String text = scanner.next();
10+
scanner.close();
11+
boolean letterFound = false;
12+
for (int i = 0; i < text.length();i++){
13+
char currentLetter = text.charAt(i);
14+
if (currentLetter =='A' || currentLetter == 'a'){
15+
letterFound = true;
16+
break;
17+
}
18+
}
19+
if (letterFound){
20+
System.out.println("This text contains A letter");
21+
}else {
22+
System.out.println("This text doesn't contain the letter A");
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)