Read a 2-character string from input into variable inString. Declare a Boolean variable isValid and assign isValid with true if inString does not contain any lowercase letters. Otherwise, assign isValid with false.
Read a 2-character string from input into variable inString. Declare a Boolean variable isValid and assign isValid with true if inString does not contain any lowercase letters. Otherwise, assign isValid with false.
Ex: If the input is FB, then isValid is assigned with true, so the output is:
Valid string
Ex: If the input is kv, then isValid is assigned with false, so the output is:
Invalid string
Note: Use inString = scnr.nextLine() to read the entire line from input into inString.
import java.util.Scanner;
public class StringChecker {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String inString;
/* Your code goes here */
if (isValid) {
System.out.println("Valid string");
}
else {
System.out.println("Invalid string");
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images