+ 1

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.

22nd Apr 2017, 12:51 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
10 Antworten
+ 9
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.
22nd Apr 2017, 4:32 PM
Rrestoring faith
Rrestoring faith - avatar
+ 7
@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);
22nd Apr 2017, 4:38 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
+ 3
thank you, that was the answer i was looking for!
22nd Apr 2017, 1:02 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
+ 2
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
22nd Apr 2017, 12:57 PM
Alejandro Herrera
Alejandro Herrera - avatar
+ 2
No problem, have fun! 😊
22nd Apr 2017, 1:04 PM
Alejandro Herrera
Alejandro Herrera - avatar
+ 1
Yeah you are totally right, sorry about that mistake and thanks for the correction 😊 @Devender Mahajan
22nd Apr 2017, 10:04 PM
Alejandro Herrera
Alejandro Herrera - avatar
+ 1
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.
23rd Apr 2017, 12:54 PM
No One
No One - avatar
0
thanks for help me guys!
22nd Apr 2017, 6:53 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
0
thanks, this is a useful explanation.
23rd Apr 2017, 1:20 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
0
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.
23rd Apr 2017, 10:11 PM
T0nd3