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
Dana Urrey
1,575 PointsStuck on IO challenge task 3, please take a look and see if you can help me out please :)
The below code works in the workspace successfully so I'm now 100% confused on what this task is looking for that I haven't included, I've tried this code in its entirety and just kept deleting anything that gave me an error, until I am whittled down to the original error "Bummer! Did you forget to pass firstName in your parameter?" which I can't seem to get past, I left in all my original comments but also added some to indicate which section is being used for the task. And I've also tried defining the strings before passing them through the readLine statement, but no go, still get a Bummer! Also as I mentioned the workspace executes this successfully allowing for input and everything I expect, but the output on the task stays blank so far....
public class Io {
public static void main(String[] args) {
Console console = System.console();
//My task code starts here
//tada! initializing firstName string
String firstName = "";
//asking user for first name
console.printf("What's your first Name?\n");
//accepting input from the user via the keyboard, and redefining firstName string as the user's input
firstName = console.readLine(firstName);
// initializing lastName string
String lastName = "";
//gotta ask for user's last name too
console.printf("\nWhat's your last Name?\n");
//accepting user input and redefining lastName string as input
lastName = console.readLine(lastName);
//printing resulting strings
console.printf("\nAwesome welcome %s %s", firstName, lastName);
//stopped my task code here
}
3 Answers
Alex Johnson
6,067 PointsI'm not sure why you ran into issues, but this worked for me:
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("Enter a first name: ");
String lastName = console.readLine("Enter a last name: ");
console.printf("First name: %s", firstName);
And when I compile and run your code on my machine it works fine (after importing java.io.Console). I guess maybe I just don't understand the problem you're having.
Alex Johnson
6,067 PointsCan you pass part three of the IO challenge by copying and pasting my code from above? If not, maybe it's a bug with Treehouse.
Dana Urrey
1,575 PointsGrrr...I'm a little irked that your's worked and mine didn't, I can see that yours is cleaner, requires less lines of code to achieve the same result but I'm still not sure I understand why one would pass and the other wouldn't. In any case I'm finally past task 3, so thank you so much for working this out with me, I really appreciate the help, and I sometimes make things harder than they need to be so I'm giving you a big "YOU ROCK!" for simplifying it for me. :) I'd have given you more than one best answer, but smart people built this forum and I can only give you one :)
Alex Johnson
6,067 PointsThanks. :-)
Dana Urrey
1,575 PointsDana Urrey
1,575 PointsOops, yeah I forgot to copy over my import, but it was such a small set java.io.Console was the only one I had anyway. It's specifically the task in the Java Basics IO challenge that is not letting me continue, I can run this in the workspace no problem but the challenge won't continue.
Thanks for checking my code :) it makes me feel better about getting with support now that I have confirmation that my code executes correctly regardless of what computer or workspace it's run from.