About Question enthuware.ocpjp.v11.2.3052 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
palmada
Posts: 2
Joined: Tue Apr 13, 2021 4:22 pm
Contact:

About Question enthuware.ocpjp.v11.2.3052 :

Post 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?"

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

uisang
Posts: 2
Joined: Wed Apr 21, 2021 2:49 pm
Contact:

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

Post by uisang »

I think only should be after contains: "[...] will return true if the input string contains only non-whitespace data?"

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

edufin166@yahoo.com
Posts: 24
Joined: Wed Sep 28, 2022 9:41 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

burlacu.valeri
Posts: 8
Joined: Tue Jan 26, 2021 7:55 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

burlacu.valeri
Posts: 8
Joined: Tue Jan 26, 2021 7:55 am
Contact:

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

Post by burlacu.valeri »

Hi, thank you very much for the answer! Now I understand. :)

soncrash
Posts: 8
Joined: Sat Aug 27, 2016 2:51 pm
Contact:

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

Post by soncrash »

I also answered incorrectly, because I had a problem interpreting the sentence in question :D

imralav
Posts: 3
Joined: Thu Dec 07, 2023 8:59 am
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 38 guests