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 - Using String Equality

Andrew Wilkerson
Andrew Wilkerson
1,504 Points

Code not exiting when "dork" is inputted

I am unable to get the code to stop and print out the message when inputting "dork" for the noun.

  String noun = console.readLine("Enter a noun:  ");
  if (noun.equals("dork")){
    console.printf("That Language is not allowed. Exiting \n\n");
    System.exit(0);
  }

4 Answers

Brendon Butler
Brendon Butler
4,254 Points

I would use equalsIgnoreCase instead of equals. As it will make the input case insensitive. You should also use %n instead of \n as it offers more operating system versatility. Other than that. From this snippit of code, things look fine.

Andrew Wilkerson
Andrew Wilkerson
1,504 Points

I was trying to follow along with the video, which is why I used equals, and I will keep in mind the %n, but I need t figure out why this won't work.

Brendon Butler
Brendon Butler
4,254 Points

He actually switches to equalsIgnoreCase and %n eventually in the tutorials. But could you post your whole code?

Andrew Wilkerson
Andrew Wilkerson
1,504 Points

Nevermind, I am used to JGRASP which saves automatically and workspace does not.

I had same issue and spent an age looking for a mistake. Turned out I forgot to save before running.