Monday, July 27, 2009

How do I print multiple integer variables to screen in Java?

I am more familiar with C# where I would:





Console.Writeline("{0}, {1}", variableOne, variableTwo);





(Or something very similar) What is the equivalent in Java?





Thanks for your help!

How do I print multiple integer variables to screen in Java?
The equivalent in Java would be:





System.out.println("" + variableOne + ", " + variableTwo);





You can just use "+" for String concatenation. As long as the leftmost part of the expression is a String (which is why I put an empty-string in front of variableOne), it will work.





There are also ways to do formatted output, but they're not generally necessary unless you're trying to get columns to line up, or print floating-point numbers to a specific number of decimal places.

tomato plants

No comments:

Post a Comment