Print out with less typing | Sololearn: Learn to code for FREE!


Print out with less typing

How can i print out multiple result without typing multiple time System.out.println? for ex. i have 4 variable, and i dont want to type 4 times System.out.println? sorry for bad english.

4/22/2017 12:51:17 PM

Benedek Máté Tóth

10 Answers

New Answer


If you want to move to another line, use \n. System.out.println(a+"\n"+b+"\n"+c+"\nThose are the variables."); That's equivalent to 4 println's. output: (whatever the values are) a b c Those are the variables.


@Alejandro, if I am not mistaken, the example that you cited above will print the sum of all four variables as they are of same type i.e., int. A minor correction is submitted: System.out.println(a+" "+b+" "+c+" "+d);


thank you, that was the answer i was looking for!


int a,b,c,d system.out.println(a+b+c+d); You have 4 variables there and with ' + ' you concatenate them printing all the values in one print


No problem, have fun! 😊


Yeah you are totally right, sorry about that mistake and thanks for the correction 😊 @Devender Mahajan


I know its a little bit late but if you have alot of values and you want something nicely formated use printf. I assume that a b c and d are ints: System.out.printf ("a:%d%n b:%d %n c:%d%n d:%d%n",a,b,c,d); chars after a % are replaced e.g %d is replaced by a decimal.


thanks for help me guys!


thanks, this is a useful explanation.


if you use eclipse you can overwrite the "toString" method and select all fields it should contain. I think Netbeans is also capable of it.