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
Prabh Bajwa
2,020 PointsSir I'm trying to make this code work in sublime-text-3 as well but it's not working there please help me?
Hello, Sir My name is Prabh and I was trying to work in Sublime-Text-3 I but this code:
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
console.printf("Hello, my name is Craig");
}
}
is not working with Sublime what should I do but this code is working just fine: public class Introductions{ public static void main(String ...args){ System.out.println("Hello, my name is Prabh"); } }
2 Answers
anil rahman
7,786 Pointsyou use the console in workspaces but do not need to in ide's
Just use the System.out.printf method to print
public class Introductions {
public static void main(String[] args) {
// Welcome to the Introductions program! Your code goes below here
System.out.printf("Hello, my name is Craig");
}
}
Also use Scanner for input from user and such.
Jeremy Hill
29,567 PointsIt looks like you need to add a String variable and have your printf statement print out hard coded String and add your variable to the end like this:
String firstName = "Craig";
console.printf("Hi, my name is %s!", firstName);
I'm assuming that is what your are trying to do.
Jeremy Hill
29,567 PointsIf you are using a IDE, I would go with using a Scanner object like anil is saying. I never have much luck using a Console object in my IDE.
anil rahman
7,786 PointsYeah, never seems to go as well, random errors haha, i still prefer using scanner anyway for reading and such so much easier. :)
Prabh Bajwa
2,020 PointsThanks sir for helping me I'm just starting Java today so it's bit difficult for me to understand this.
Prabh Bajwa
2,020 PointsPrabh Bajwa
2,020 PointsThank You sir thank you so much.