4.12: Comparing Characters And String Objects

7 September 2022
4.7 (114 reviews)
20 test answers

Unlock all answers in this set

Unlock answers (16)
question
What's the difference in ASCII value between 'E' and 'A'? (consult a table of ASCII values): http://www.asciitable.com
answer
4
question
What's the difference in ASCII value between 'e' and 'a'? (consult a table of ASCII values):
answer
4
question
What's the difference in ASCII value between '3' and '0'? (consult a table of ASCII values):
answer
3
question
What's the difference in ASCII value between '6' and '0'? (consult a table of ASCII values):
answer
6
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is a upper-case letter.
answer
(x>='A' && x<='Z')
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is a lower-case letter.
answer
(x>='a' && x<='z')
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is a decimal digit (0-9).
answer
(x>='0' && x<='9')
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is an octal (Base 8) digit (0-7).
answer
(x>='0' && x<='7')
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is a letter.
answer
(x>='A' && x<='Z') || (x>='a' && x<='z')
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is alphanumeric , that is either a letter or a decimal digit.
answer
(x>='A' && x<='Z') || (x>='a' && x<='z') || (x>='0' && x<='9')
question
Assume that c is a char variable that has been declared and already given a value . Write an expression whose value is true if (c == 'n')and only if c is an newline character .
answer
(c == 'n')
question
Assume that c is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if c is a space character .
answer
c == ' '
question
Assume that c is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if c is a tab character .
answer
(c=='t')
question
Assume that c is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if c is what is called a whitespace character (that is a space or a tab or a newline-- none of which result in ink being printed on paper).
answer
(c == ' ' || c== 'n' || c == 't')
question
Assume that c is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if c is NOT what is called a whitespace character (that is a space or a tab or a newline-- none of which result in ink being printed on paper).
answer
!(c == ' ' || c== 'n' || c == 't')
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is NOT a upper-case letter.
answer
!(x >= 'A' && x <='Z')
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is NOT a letter.
answer
!((x >= 'A' && x <='Z') || (x >= 'a' && x <='z'))
question
Assume that s is a string . Write an expression whose value is true if and only if the value of s would come between "mortgage" and "mortuary" in the dictionary.
answer
s > "mortgage" && s < "mortuary"
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is NOT a letter.
answer
((x>='A' && x<='Z') || (x>='a' && x<='z'))
question
Assume that x is a char variable that has been declared and already given a value . Write an expression whose value is true if and only if x is an hexadecimal (Base 16) digit (0-9 plus A-F or a-f).
answer
( ( x>='0' && x<='9') || ( x>='a' && x<='f' ) || ( x>='A' && x<='F') )