Java Java Basics Perfecting the Prototype Censoring Words - Using Logical ORs

Anas Rida
Anas Rida
8,183 Points

What am I doing wrong?

if (adjective.equals("naughty") || (adjective.equals("bad")) { console.printf("You are not allowed to use this kind of language you dirty rascal!!!!!\n\n"); System.exit(0); }

I am typing this code, but I am getting the following error

TreeStory.java:21: error: ')' expected

the arrow points to the curly bracket. did I miss something??

Thanks in advance

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,352 Points

Hi Anas,

add a third round bracket to the if statement

if (adjective.equals("naughty") || (adjective.equals("bad"))) {  // a third round bracket added

console.printf("You are not allowed to use this kind of language you dirty rascal!!!!!\n\n"); 
System.exit(0); 
}

Let me know if this was the solution

Grigorij

Anas Rida
Anas Rida
8,183 Points

Thanks you for answering my question. I was actually able to figure it out. I added a third bracket and it worker. I also removed the bracket after the || and left two brackets at the end, and it also worked. However I am not sure which is considered the best solution, and less problematic in the future. If you could shed some light on this I would be very grateful.

Grigorij Schleifer
Grigorij Schleifer
10,352 Points

Hi Anas,

try to write code that is easy to write and to read. So you have already done the best solution by deleting a bracket and made your code less "heavy" :)))

Grigorij