This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with System.out.print command

 
sarah sturgeon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sarah,
Welcome to CodeRanch!

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

 
sarah sturgeon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne.
 
Jitendra Jha
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:

Or using the "new" printf method:
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic