Page 1 of 1

About Question enthuware.ocpjp.v11.2.3052 :

Posted: Sun Apr 18, 2021 8:15 am
by palmada
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?"

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Mon Apr 19, 2021 9:01 pm
by admin
palmada wrote:
Sun Apr 18, 2021 8:15 am

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.

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Wed Apr 21, 2021 3:06 pm
by uisang
I think only should be after contains: "[...] will return true if the input string contains only non-whitespace data?"

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Wed Apr 21, 2021 10:54 pm
by admin
If you frame it that way, it doesn't tell what should happen if the input stream does not contain only whitespace data.

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Fri Mar 10, 2023 3:03 pm
by edufin166@yahoo.com
I dont understand...

non-whitespace data = " x x x "

!str.isEmpty() -> " x x x " or " " -> FALSE, therefore, TRUE

!str.isBlank() -> " x x x " -> FALSE, therefore TRUE
!str.isBlank() -> " " -> TRUE, therefore FALSE

???? Accpding above, either Empty or Blank are TRUE??? Am I wrong?

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Fri Mar 10, 2023 8:01 pm
by admin
Sorry, but I did not understand what exactly are you getting at. Please post the complete code that you are trying to run.

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Mon Mar 27, 2023 11:29 am
by burlacu.valeri
Hi,

The method isBlank() - Returns true if the string is empty or contains only white space codepoints, otherwise false.

For example:
String s = " ";

So, which variant is correct and why? :/
1 => [the input string contains non-whitespace data?]
or
2=> [the input string contains whitespace data?]

What difference is between non-whitespace and whitespace?

Thx.

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Mon Mar 27, 2023 8:28 pm
by admin
"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.

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Tue Mar 28, 2023 1:37 am
by burlacu.valeri
Hi, thank you very much for the answer! Now I understand. :)

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Wed Mar 29, 2023 8:28 am
by soncrash
I also answered incorrectly, because I had a problem interpreting the sentence in question :D

Re: About Question enthuware.ocpjp.v11.2.3052 :

Posted: Thu Dec 14, 2023 12:00 am
by imralav
soncrash wrote:
Wed Mar 29, 2023 8:28 am
I also answered incorrectly, because I had a problem interpreting the sentence in question :D
The same for me. It should really read "any non-whitespace data", because it is easy to interpret it as "only non-whitespace data" instead.