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

Program exiting even when words other than "dork" is used for noun.

I can't happen to figure out why the program still exits even when dork is not used, copied the code in the video.

Code:

String name = console.readLine("Enter a name: "); String adjective = console.readLine("Enter an adjective: "); String noun = console.readLine("Enter a noun: "); if(noun.equalsIgnoreCase("dork")); { console.printf("This type of language is not allowed. Exiting program... \n\n"); System.exit(0); }

1 Answer

Adomas Domeika
Adomas Domeika
6,151 Points
if(noun.equalsIgnoreCase("dork")); <--- this causes the problem ( the semicolon )

{ console.printf("This type of language is not allowed. Exiting program... \n\n"); System.exit(0); }