Which of the following expressions can be inserted in the above code so that the validateInput method will return true if and only if the input string contains non-whitespace data?
I understood the question as meaning "return true if the string contains any non-whitespace data". This means that if it should return true on, for example " t e s t " since it contains non-white space data.
Did you mean to ask "will return true if the input string contains non-whitespace data and only non-whitespace data?"
I understood the question as meaning "return true if the string contains any non-whitespace data". This means that if it should return true on, for example " t e s t " since it contains non-white space data.
Yes, you understood correctly. Yes, " t e s t " should return true.
The "only if" of the "if and only if" part is to convey that a string containing only whitespace data should not cause true to be returned.
>Did you mean to ask "will return true if the input string contains non-whitespace data and only non-whitespace data?"
No.
If you like our products and services, please help us by posting your review here.
"whitespace" means characters such as space, tab, new line. Non-whitespace means the opposite.
As per the problem statement, the validateInput(String str) method should return true if and only if the input string contains non-whitespace data. Meaning, the following strings should cause the validateInput method to return true:
"test" <- no whitspace at all
" t e s t " <- some whilespace but non-whitespace chars are also present
and the following strings should cause the validateInput method to return false:
"" <- empty string. Both isBlank and isEmpty will return true.
" " <- the string is not empty but there is no non-whitespace in this string. isBlank will return true but isEmpty() will return false, and !str.isEmpty() will be true, which is not what we want.
So, !str.isBlank() is the only correct option.
If you like our products and services, please help us by posting your review here.
This question is worded wrong. when it says, if and only if it does contain non-whitespace, it means that the string "aaa aaa" cannot return true. Because the string "aaa aaa" has a whitespace. But if you try !"aaa aaa".isBlank(), the result is true. Which means that there is no right answer to this question
No, please read the problem statement again carefully. It is worded correctly. Please go through above messages also.
"aaa aaa" should return true because it does conain non whitespace data.
The problem statement doesn't say that it should contain only non whitespace data.
If you like our products and services, please help us by posting your review here.