This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help with System.out.print  command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with System.out.print  command" Watch "Help with System.out.print  command" New topic

Help with System.out.print command

sarah sturgeon

Joined: Aug 27, 2011
Posts: 11
Hi every body

I hope everyone is doing great. Please consider the following

Int a= 11,
String b= " Joe";
String c=" Ashley dr";

The goal is to pass these variables as parameters to " System.out.println command " so that we can display on screen the output: 11 Joe Ashley dr

How can i pass these variables as parameters ?

I tried:

System.out.println ( a, " ", b, " ", c);

But compiler kept giving error.

I hope someone could help with this.

Thanks and have a great weekend.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32481

Welcome to CodeRanch!

That's close. You build one string with a + like:

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
sarah sturgeon

Joined: Aug 27, 2011
Posts: 11
Thanks Jeanne.
Jitendra Jha
Ranch Hand

Joined: Jan 28, 2007
Posts: 91
The print statement's argument will finally be rendered as String.
Hence "+" should be used for concatination as already pointed out in the post above

Rob Spoor

Joined: Oct 27, 2005
Posts: 20078

Jeanne Boyarsky wrote:

Or using the "new" printf method:

How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11855

sarah sturgeon wrote:But compiler kept giving error.

Please, in the future, tell us exactly what the error says. Believe it or not, those error messages tell you a LOT about what the problem is. Learning how to read them is a valuable skill that will save you hours of time in the future.

Simply saying "i get an error" is often meaningless. There are too many things it could be for anyone to give you any real help (most of the time).

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Have you checked out Aspose?
subject: Help with System.out.print command
It's not a secret anymore!