forked from angiejones/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLetterSearch.java
More file actions
37 lines (30 loc) · 914 Bytes
/
Copy pathLetterSearch.java
File metadata and controls
37 lines (30 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package chapter4;
import java.util.Scanner;
/*
* LOOP BREAK
* Search a String to determine if it contains the letter ‘A’.
*/
public class LetterSearch {
public static void main(String args[]){
//Get text
System.out.println("Enter some text:");
Scanner scanner = new Scanner(System.in);
String text = scanner.next();
scanner.close();
boolean letterFound = false;
//Search text for letter A
for(int i=0; i<text.length(); i++){
char currentLetter = text.charAt(i);
if(currentLetter == 'A' || currentLetter == 'a'){
letterFound = true;
break;
}
}
if(letterFound){
System.out.println("This text contains the letter 'A'");
}
else{
System.out.println("This text does not contain the letter 'A'");
}
}
}