I need help with a few nested for loop questions, because I don't understand how to obtain the correct answers. I need to know how to do these by calculator and pencil for upcoming tests.
String output = "";
for(int a = 1; a < 3; a++)
for(int b = 1; b < 3; b++)
output += (a*b) + "";
int total = 0;
for(int c = 3; c < 9; c= c+3)
for(int d = 1; d <= c; d++)
total = total + d;
It's not an answerable question but to explain you, First statement will add the each result of multiplication in loop like,
1*3 and again
"" at last means a sort way to convert output into String to append it with
output. And answer will be 1224
Second is also the same, but it adds the result instead of concatenating, and loops till the value of
d reaches to value of
c and the output will be 27 as you say.