Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
I have learned java before in my school but it's totally different, I didn't get it why we are using console & printf.
What I learned before in java is System.out.print method but not like this.
It's just an alternative way of printing and getting input, when it comes to programming you'll often find that there are lots of slightly different ways to accomplish the same type of task.
The console class makes it easy to get input from the console, it is simpler than the other common alternative which is to use a Scanner object. The disadvantage though is that for various reasons too complicated to get into here the console class usually does not work when you run Java programs through an IDE. That is not a problem for Treehouse since they don't use IDEs for the basic courses, but it would be for any course which does.
If your school thought you Java and used some sort of Java IDE like IntelliJ or Eclipse then that would be the reason why they never used the console class.
And you can use printf without using the console class through the System.out.printf method. It works exactly the same as the console printf.
They do almost the same thing.
Just keep in mind when you use
console.printf, you can format in stuff. For example, if you do this...
String name = "Alex"; console.printf("Hello there, %s! Nice to meet you!", name);
The output will be...
Hello there, Alex! Nice to meet you!
%s in the string is like a placeholder where you can insert whatever you want. In this case, you insert
Remember: The string with the placeholder and the placeholder's value are separated by commas because the
printf method take two of more arguments.
printf is short for "print format [string]". There is also a
println function in
console that just prints whatever you tell it to print. (
println stands for print line.)
I hope this helps. ~Alex
umm! I own a mac and I don't know how to code local, you know. in my computer but thank tho!