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

Code wont compile

import java.io.Console;

public class TreeStory {

public static void main(String[] 
    Console console = System.console();
  int age = 12;
  if (age < 13);    {
  printf("Sorry, but you must be 13 to use this program.\n");
  System.exit(0);

  }

1 Answer

Hi tyler,

I see some errors:

import java.io.Console;

public class TreeStory {

public static void main(String[] args) {
    Console console = System.console();
  int age = 12;
  if (age < 13)   { // semicolon deleted
  console.printf("Sorry, but you must be 13 to use this program.\n"); // variable name console added
  System.exit(0);
  }
} // curly bracket added

And there is a logical error:

The condition will always be true, because your age variable is hardcoded to 12, and 12 is less then 13, so the printf method will always be activated.

And try to add a String formatter for the printf method.

Let me know if you need more help. We can work it out together.

Grigorij