I am figuring how to print the results of 4 integers on separate lines by typing only one System.out.println
(I guess typing less is better for coders).
Expected Output :
43
1
19
13
My code:
class JavaApplication1 {
public static void main(String[] args) {
int a,b,c,d;
a = -5 + 8 * 6;
b = (55+9) % 9;
c = 20 + -3*5 / 8;
d = 5 + 15 / 3 * 2 - 8 % 3 ;
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
}
You can do i with several ways :
This will print the variable and between each a
new-line char
:You can also use method reference and
Arrays
, this will create a dynamic List from the array composed of your 4 variables, and applySystem.out::println
to each one :or
Use a basic
for each loop
can also be a way :Print with
format
also :