Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Censoring Words - Looping Until the Value Passes

boolean method

Hello, is the any disadvantage in this using with "()" or not in this lesson using with '()' but when I remove its work http://teamtreehouse.com/library/java-basics/perfecting-the-prototype/censoring-words-looping-until-the-value-passes

boolean isInvalidWord = ( noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk") );

boolean isInvalidWord = noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk");

David Clausen
David Clausen
11,403 Points

The first line using () in java is valid. You can test it with

boolean test = (false|| true);

So we need more code to see, if you can paste your code. Once pasted put ```Java next to each other (the key next to one) and close the code with ```.


If I can help then.

EDIT: Also I went to your lesson and tried it out in workspaces with no issue. Lets see your code for sure. Sometimes when debugging something it good to print something out to test where it went wrong.


 String noun = console.readLine("Enter a noun:  ");

      boolean isInvalidWord = (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk"));
      //Test to see what boolean isInvalidWord currently is before a conditional statement
      console.printf("isInvalidWord is set to: " + isInvalidWord+"\n");

      //Rest of the code
      if (noun.equalsIgnoreCase("dork") ||
          noun.equalsIgnoreCase("jerk")) {
        console.printf("That language is not allowed.  Exiting. \n\n");

Here we will see it printed out before we get to any loops or checks, so you know 100% if its being evaluated correctly. It may turn out what you suspect the problem is, is very quite different and located somewhere else.

1 Answer

Hi Syalih,

In this case does not make any diference but some time you'll need the brackets for eg:

Is not the same if you make this in a variable integer int a = 2 + 4 / 3;

And if you make this

int a = (2+4)/3

the brackets Separate in terms like in math. In a case you use a boolean like you use it there is not difference BUT if you do this for eg: Boolean test = (false|| true) && (false);

In this case Boolean value will be FALSE. You have to learn Boolean algebra http://en.wikipedia.org/wiki/Boolean_algebra

I hope I helped!


p.d: Sorry my bad english haha