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

Error: "else without if"

import java.io.Console;

public class TreeStory 
{

    public static void main(String[] args) 
    {

        Console console = System.console();
        String name = console.readLine("Enter your name:  ");
        String adjective = console.readLine("Enter an adjective:  ");
        String noun = console.readLine("Enter a noun:   ");
      if (noun.equalsIgnoreCase("*****")) //word removed by Moderator for being inappropriate for the Community Forum
      {
        console.printf("Don't use this language again pls \n");
        String Question = console.readLine("Do you gonna use those word again?    ");
        if (Question.equalsIgnoreCase("Yes"))
        {
          System.exit(0);
          else;
          {
            noun = console.readLine("Enter a noun:   ");
              console.printf("%s is a very %s %s \n ", name, adjective, noun);
          }
        }
      }
    }
  }

TreeStory.java:20: error: 'else' without 'if'
else;
^
1 error

Moderator added markdown for readability. Please refer to the Markdown Cheatsheet before posting code to the forum! And edited content of code to comply with Terms of Use.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Please have a look at the Markdown CheatSheet before posting code. This is the second post I've added the Markdown to. Also, the second time, I've edited your post to remove offensive language as per the Terms of Use. Please review both.

:dizzy:

1 Answer

Nancy Melucci
PLUS
Nancy Melucci
Courses Plus Student 36,143 Points

Replace the semicolon after "else" (after System.exit();) with a french brace...I think that will fix it. It takes time to learn to check all the if/else if/else braces. I am just getting the hang of it.