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 trialNithin Katta
306 PointsEven the code is correct its bumming up with error
import java.io.Console;
public class Introductions {
public static void main(String[] args) {
Console console = System.console();
// Welcome to the Introductions program! Your code goes below here
String firstName = console.readLine("What is your name ");
console.printf("Hello my name is %s\n", firstName);
console.printf ("%s learning Java\n", firstName);
} }
// I have imported java.io.Console for you. It is a variable called console.
import java.io.Console;
public class Introductions {
public static void main(String[] args) {
Console console = System.console();
// Welcome to the Introductions program! Your code goes below here
String firstName = console.readLine("What is your name? ");
console.printf("Hello my name is %s\n", firstName);
console.printf ("%s learning Java\n", firstName);
}
}
5 Answers
Steve Hunter
57,712 PointsHi there,
The challenge asks you to Declare a variable that is named the camel-cased version of "first name". Store the user's first name into this new variable using console.readLine. Do just that - no need for any other code. Just one line reading user input and storing it in a named variable.
Make sense?
Steve.
Nithin Katta
306 PointsStill not
Steve Hunter
57,712 PointsPost your code - let's figure out what's wrong.
Steve.
Nithin Katta
306 Points// I have imported java.io.Console for you. It is a variable called console.
import java.io.Console;
public class Introductions {
public static void main(String[] args) {
Console console = System.console();
// Welcome to the Introductions program! Your code goes below here
String camel-cased = console.readLine("Nithin");
console.printf("Hello my name is %s\n", camel-cased);
console.printf ("%s learning Java\n", camel-cased);
console.printf("End");
}
}
Steve Hunter
57,712 PointsHi Nithin,
I'll go back to my initial answer - you're doing too much code!
You have a console object provided and you're being asked to create a variable which is called the camel case version of 'first name' - that would look like firstName
.
You want to assign a value into it by reading user input; you've got that bit, sort of. You could use console.readLine("What is your first name?: ");
Putting all that together, you get:
String firstName = console.readLine("What is your first name?: ");
That's task one done.
Make sense?
Steve.
Nithin Katta
306 Pointsyes thanks
Steve Hunter
57,712 PointsCool - good luck with the next tasks!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsThen add the next tasks to the first task code - don't overwrite anything unless the instructions ask you to. Here, you create another variable for the last name then do some outputting with
printf
.