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
chidera Ani
Courses Plus Student 606 PointsCensoring words. am trying to catch the word "dork" but the program just ignores it and runs the next line. need hlp.
import java.io.Console;
public class TreeStory {
public static void main(String[] args) { Console console = System.console(); /* Some terms: noun - Person, place or thing verb - An action adjective - A description used to modify or describe a noun Enter your amazing code here! */ String ageAsString = console.readLine ("How old are you?");
int age = Integer.parseInt(ageAsString);
if (age < 13) {
console.printf(" sorry you must be 13 and above to use this code \n");
System.exit(0);
}
String name = console.readLine("Enter your name: ");
String adjective = console.readLine("Enter an adjective: ");
String noun = console.readLine("Enter a noun: ");
if(noun.equals("dork")) {
console.printf("This language is not allowed exiting..\n");
System.exit(0);
}
String adverb = console.readLine("Enter an adjective: ");
String verb = console.readLine("Enter an adverd ending in-ing: ");
console.printf("your TreeStory:\n---------------\n");
console.printf("%s is a %s %s. ", name, adjective, noun);
console.printf("they are always %s %s. \n", adverb, verb);
}
}
2 Answers
Blake Larson
13,014 PointsLooks right just remember equals method is case sensitive so if you enter "Dork" and you blocked "dork" the program will allow it. If that's your problem use the equalsIgnoreCase method.
Blake Larson
13,014 PointsIt looks correct to me. Sometimes it can be as simple as saving the file. If the if statement was wrong you would get a syntax error in your compiler. I don't think you should be passing directly to the next String.
chidera Ani
Courses Plus Student 606 PointsHi Blake thanks for the help it worked. Then i implemented the equalsIgnoreCase method and its not working. I think this is not saving properly.. wish this can be fixed as i do click on save multiple times.
chidera Ani
Courses Plus Student 606 Pointschidera Ani
Courses Plus Student 606 Pointshi i entered dork" and the system allowed it..that's what am trying to figure out.