
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 nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

- Extend to cast the double to an integer, and output that integer. Enter integer: 99 Enter double: 3.77 Enter character: z Enter string: Howdy 99 3.77 z Howdy Howdy z 3.77 99 3.77 cast to an integer is 3arrow_forwarda) Give an example of a string that is neither in the language of R nor in S. b) Give an example of a string that is in the language of S but not R. c) Give an example of a string that is in the language of R but not S. d) Give an example of a string that is in the language of R and S. e) Design a regular expression that accepts the language of all binary strings with no occurrences of 010.arrow_forwardRead a 2-character string from input into 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 y-, then isValid is assigned with true, so the output is: Valid string Ex: If the input is 21, then isValid is assigned with false, so the output is: Invalid string Note: Use getline(cin, inputString) to read the entire line from input into inputString. #include <iostream>#include <string>#include <cctype>using namespace std; int main() { string inputString; /* Your code goes here */ if (isValid) { cout << "Valid string" << endl; } else { cout << "Invalid string" << endl; } return 0;}arrow_forward
- The expressions string[0] and string[:1] are the same. Select one: True Falsearrow_forwardYou are given a string ternary_expr which represents a random nested ternary expression, you need to evaluate this expression, and report the result. Assumption can be as follows: ● ternary_expr only contains digits, ‘?’, ‘:’, ’T’, ‘F’ where ’T’ is true and ‘F’ is false. ● ternary_expr contains only one-digit numbers (i.e. in the range [0, 9]) The ternary expressions group right-to-left, and the result of the expression will always evaluate to either a digit, 'T' or 'F'. Requirements 1. Way of modeling the problem with the cost implications without using Stacks.arrow_forward7. Let the statements A, B be given by A: not(p or q), B: (not p) or q. Let T = true, F = false. If p = T and q = F, then O A = T, B = T O A = F, B = T O A = F, B = F O A= T, B = Farrow_forward
- In Programming When you work with text, sometimes you need to determine if a given string starts with or ends with certain characters. You can use two string methods to solve this problem: .startswith() and .endswith()?arrow_forwardRead a 2-character string from input into variable userString. Declare a Boolean variable isValid and assign isValid with true if userString does not contain any uppercase letters. Otherwise, assign isValid with false. Ex: If the input is 86, then isValid is assigned with true, so the output is: Good string Ex: If the input is BQ, then isValid is assigned with false, so the output is: Bad string Note: Use getline(cin, userString) to read the entire line from input into userString. #include <iostream>#include <string>#include <cctype>using namespace std; int main() { string userString; /* Your code goes here */ if (isValid) { cout << "Good string" << endl; } else { cout << "Bad string" << endl; } return 0;}arrow_forwardplese code in python The midfix of 3 is the middle 3 characters of a string. Given a string input, output the middle three characters of that string. Assume the word length is always odd and at least three characters. Ex: If the input is: xxxtoyxxx the output is: Midfix: toyarrow_forward
- In programming you work with text, sometimes you need to determine if a given string starts with or ends with certain characters. You can use two string methods to solve this problem: .startswith() and .endswith()?arrow_forwardWrite a function that accepts a pointer to an integer array and the array's size as arguments. The function should allocate a new array, copy the items from the original array to the new one in reverse order, and then deallocate the original array.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





