aspose file tools*
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
Author

Help with System.out.print command

sarah sturgeon
Greenhorn

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
Marshal

Joined: May 26, 2003
Posts: 30957
    
158

Sarah,
Welcome to CodeRanch!

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



[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
sarah sturgeon
Greenhorn

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


Jitendra
SCJP1.5
SCWCD1.5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Jeanne Boyarsky wrote:

Or using the "new" printf method:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11480
    
  16

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Help with System.out.print command