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
Sha Sud
4,175 PointsCommunication problem code not working ?
import java.io.Console; public class intro{ public static void main(String [] args) { Console console=System.console(); String firstName=console.readLine("whats your name?");
console.printf("Hello,my name is %s\n",firstName);
console.printf(" %s is learning how to write Java\n",firstName);
}
}
17 Answers
Jeremy Hill
29,567 PointsSo you should now have:
String firstName = "Sha";
console.printf("%s is learning how to write Java", firstName);
Jeremy Hill
29,567 PointsYour code runs in workspace, I've tried to use java.io.Console in my own IDE but I never have much luck. I usually use java.util.Scanner in my IDE and it works great.
Rohit Bokam
1,728 Pointsdid you check case sensitivity , because in a few places , you begun with lowercase instead of uppercase , i ain't sure , that's the issue or not , but just try changing it to uppercase wherever required , for example class name , Java.io.Console. I'll check further for any errors meanwhile.
Sha Sud
4,175 PointsThanks Rohit but it is not working
Jeremy Hill
29,567 PointsAre you trying to run the program in your own IDE or workspace?
Sha Sud
4,175 Pointsworkspace
Jeremy Hill
29,567 PointsCan you repost all of your code using the "java" format (you can click the "Markdown Cheatsheet" link at the bottom of this page to learn how to format it). I didn't find anything wrong with your code but I'm hoping to get a better look at it after it is all formatted correctly. Instead of typing html after your tick marks just type "java". Make sure that there is a space after you first set of tick marks and a space before the last set.
This will help us out more.
Sha Sud
4,175 Pointsthe code is working in the workspace but it is not working in the exercise question which is given by the teamtreehouse when i am submitting the code communication problem is there.
Jeremy Hill
29,567 PointsI see, ok the next thing you can do is make sure that all of your text matches up with theirs; if you have a period out of place or an extra space they make consider that to be wrong- they can be a little picky at times. Just check over your text to make sure that it aligns with theirs exactly. By text I mean: Hello,my name is
You don't have a space after your comma. They may be counting off for that...
Sha Sud
4,175 Pointsi have to write the comments also in the code?
Jeremy Hill
29,567 PointsI can't click on the challenge to see what it is that they are asking for specifically, but sometimes they will tell you what text they want in a user prompt as well as output. If they told you how to ask for the user's name and how they want you to do the output just make sure that you type as they have it, for instance, they may say something like:
"Add a prompt that says: 'Enter your name: ' "
If you don't type it exactly like the instructions tell you to then that might be why you aren't getting it right, for instance, if you type it like this: console.readLine("Enter some name:"); instead of: "console.readLine("Enter your name:");
they might mark it off because it doesn't match the way that the instructions told you to type it.
Does that make sense to you?
Sha Sud
4,175 Pointsthese are the errors : JavaTester.java:73: error: illegal start of expression import java.util.Scanner ; ^ JavaTester.java:73: error: not a statement import java.util.Scanner ; ^ JavaTester.java:74: error: illegal start of expression public class intro{ ^ 3 errors
Jeremy Hill
29,567 PointsOkay delete the " import java.util.Scanner ", workspaces doesn't use that. They use the Console object. Try that first and see what happens.
Sha Sud
4,175 Pointsnow the errors are: JavaTester.java:73: error: illegal start of expression import java.io.Console; ^ JavaTester.java:73: error: not a statement import java.io.Console; ^ JavaTester.java:74: error: illegal start of expression public class intro{ ^ 3 errors
Jeremy Hill
29,567 PointsTry commenting out your import statement and your class header along with the curly braces that go with it. I'm thinking that you just need the raw code in there- I think that they might already have those other things in there behind the scenes.
So just type: console.readLine(); statement and then the console.printf(); statement and submit it that way without anything else.
Sha Sud
4,175 Pointsnow recheck work is coming error is: Bummer! Did you create a String variable named firstName set equal to your name? how to do this?
Jeremy Hill
29,567 PointsI'm going to type what I think your code should have based off of what I know:
String firstName = console.readLine("What is your first name?");
printf("%s is learning how to write Java", firstName);
Try that and see what it says.
Jeremy Hill
29,567 PointsMake sure that your workspace is empty before you paste that in there.
Sha Sud
4,175 Pointsnow the error is : JavaTester.java:74: error: cannot find symbol printf("%s is learning how to write Java", firstName); ^ symbol: method printf(String,String) location: class JavaTester Note: JavaTester.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. 1 error
Jeremy Hill
29,567 PointsOkay change the first line to :
String firstName = "Sha";
Sha Sud
4,175 Pointsnow its working thank u i want to ask u that u have submited each and every question like this and succesed
Jeremy Hill
29,567 PointsI'm trying to understand your question, are you asking how I help answer people's questions or how I am able to get through the challenges?
Sha Sud
4,175 Pointshow u are able to get through the challenges?
Sha Sud
4,175 Pointscan u give the answer for this: Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!" i have done: String firstName = "Sha"; console.printf(" \"%s can code in Java!\"", firstName);
Jeremy Hill
29,567 PointsI would type it this way:
String firstName = "your name";
console.printf("%s can code in Java!", firstName);
The '\' is an escape character. I don't think it is needed in the code that you are doing right now; unless you are needing to add a new line character which would be: '\n'
That causes the output to start a new line.
When you use: /" it adds quotes to your string; the code challenge didn't ask for that however.
Jeremy Hill
29,567 PointsWhat is most helpful is paying close attention to what they are asking in the challenges. I'm sure if you go back to the previous challenge it will probably say somewhere that they have already declared a Console object so that would tell you that you don't need to worry about that. We had to remove your import statement because it was conflicting with their workspace compiler/tester. That was kind of how I figured out what was going on. When you get stuck on a challenge there is a place somewhere that lets you ask the 'Community' when you click there and follow the prompts it will allow others to click on that challenge and see what is going on. There wasn't a place for me to go into the challenge on this one so it made it a little more difficult.
My advice is to follow the instructions in the challenges very carefully, it's easy to miss things. If you need help click ask community.
I hope that helps.
Sha Sud
4,175 Pointsthank u
Sha Sud
4,175 Pointscan u give the answer for this: Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!" i have done: String firstName = "Sha"; console.printf(" \"%s can code in Java!\"", firstName); the error is: Bummer! java.util.IllegalFormatFlagsException: Flags = ' ' ()
Divine Ngocho Zumbi
Courses Plus Student 307 Pointsi think you just have to write System.out.printf("<Your Name> can code in Java!");
Jeremy Hill
29,567 PointsJeremy Hill
29,567 PointsI believe what I just posted is what you need to pass the challenge. If it doesn't pass then just click on reset code and then click inside the window and paste it again and see how that does.