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 Conditional ints

Stuart Jessiman
Stuart Jessiman
465 Points

HI there What is the syntax for doing task 2 of 3 in basic Java. The logic is understood, I can do the syntax.

I've created an int value of numberOfPeople = 3. it then asks me to see if there are less than 3 people. If so their table is ready. So I create a console.readline to get the value and then see if the int value is equal to, great or less than int numberOPeople. Then write a console printf to give the answer. It doesn't work. Please advise.

Thanks very much.

This way of learning is slow. I could be given the answer. After all, I'm looking to get an appreciation of Java. I'm not looking to become a developer. I really wish I could put on.

Conditional.java
int numberOfPeople = 3;

int = console.readline    

if {


}

1 Answer

You need to add parameters to your if statement like this :) If the information inside your parameter is true (numberofPeople is less than 4), it will run the code inside the curly braces.

if (numberOfPeople < 4){ console.printf("Your table is ready"); }

Anders Björkland
Anders Björkland
7,481 Points

As you said, there should be a statement to go along with that if, it's pretty lonely at the moment.

This line wants some attention too:

int = console.readline

int is the type of a variable, like the type of the variable numberOfPeople. console is a reference variable. It means that it is actually referencing an object which has methods you can call upon it. That is what you do by putting a . after it. Then the method-name follows the period. Every method has these (). The braces are used so a method can use what you put inside the braces. There are many methods that don't take any arguments so the braces are left empty, others do take an argument, readLine() works either way. Each statement in java is ended with a semi-colon, so the line there should look like this:

numberOfPeople = console.readLine();  

BUT, you don't really need a console here. The exercise just checks if you instantiate your variable with a value less than 4.