• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with System.out.print command

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.





"
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeanne.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:


Or using the "new" printf method:
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
reply
    Bookmark Topic Watch Topic
  • New Topic