+ 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.
10 Réponses
+ 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.
+ 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);
+ 3
thank you, that was the answer i was looking for!
+ 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
+ 2
No problem, have fun! 😊
+ 1
Yeah you are totally right, sorry about that mistake and thanks for the correction 😊 @Devender Mahajan
+ 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.
0
thanks for help me guys!
0
thanks, this is a useful explanation.
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.