Texts:
Read a 2-character string from input into the variable inputString.
Declare a Boolean variable isValid and assign isValid with true if inputString contains a lowercase letter. Otherwise, assign isValid with false.
Ex: If the input is xZ, then isValid is assigned with true, so the output is: Good string.
Ex: If the input is #X, then isValid is assigned with false, so the output is: Bad string.
Note: Use inputString = scnr.nextLine() to read the entire line from input into inputString.
String wordString is read from input. If wordString does not contain the character 'p' at or after index 1, then output:
Character 'p' is not found at or after index 1.
Otherwise, output:
"Starting at index 1, the first occurrence of character 'p' is at index [the index of the first occurrence of 'p' at or after index 1 in wordString]"
End with a newline.
Ex: If the input is punishment, then the output is:
Character 'p' is not found at or after index 1.
Ex: If the input is bookkeeping, then the output is:
Starting at index 1, the first occurrence of character 'p' is at index 7.
1 import java.util.Scanner;
2
3 public class FindCharacter {
4 public static void main(String[] args) {
5 Scanner scnr = new Scanner(System.in);
6 String wordString;
7 int index;
8
9 wordString = scnr.next();
10
11
12
13
14
15 }