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 trialniranjan Somashekar
138 Pointsstuck
thanks in advance
// I've imported java.io.Console for you. It is stored in a variable called console for you.
name= "niranjan";
console.printf readLine= ("what is your name?");
1 Answer
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsPlease take a look in a video once more, the way Craig inputs variables.
You declare variable using Type VariableName
syntax:
String name;
Your code
name= "niranjan";
will work only with declaration above:
String name;
name= "niranjan";
Most of the methods in java are called like : methodName(argument)
or many arguments
console.printf readLine= ("what is your name?");
This is not call of the method console.printf readline
...
You have to do this:
console.readLine();
As argument to readLine
method, you put phrase that will be printed before you type your input from keyboard:
console.readLine("Please enter a word: ");
I will help you with the first task to get started.
So, you first declare a variable called name
String name;
Second, you store user input in that variable. In order to do that you have to know that console.readLine()
returns whatever user types...And in order to store that in our name
variable we have to use equal:
name = console.readLine("Please type your name: ");
One can also combine declaration and assignment:
String name = console.readLine("Please type your name: ");
That will solve first task of challenge. Please re-watch lecture videos, and google about java as well, if things are not clear...