191k views
0 votes
50 POINTS

1. int f = 8;

out.println("$"+f+10);

what is the output and how did you get that?


2. int e = 12;

e = 15;

out.println(e);

what is the output and how did you get that?


3. int i =7, j = 10;

j *=i+2;

out.println( i+" "+j);

what is the output and how did you get that?



THOUGHTFUL ANSWER OR NOT REPORT

User Hajikelist
by
7.7k points

1 Answer

5 votes

The output of the code is "$810".

The expression "$" + f + 10 is evaluated as follows:

' f ' is an integer with the value of 8, so f + 10 evaluates to 18.

The string "$" is concatenated with the result of f + 10, resulting in the string "$18".

The final result is printed to the console using the println method, so the output is "$810".

The output of the code is "15".

The code sets the value of ' e ' to ' 12 ' in the first line, then re-assigns it to ' 15 ' in the second line. The final value of ' e ' is ' 15 '.

In the third line, the value of ' e ' is printed to the console using the ' println ' method, so the output is "15".

The expression j *= i + 2 means to multiply j by the value of i + 2 and assign the result back to j. So in this case, j becomes j * (i + 2) = 10 * (7 + 2) = 10 * 9 = 90.

In the third line, the values of i and j are concatenated with a space in between and printed to the console using the println method, so the output is "7 29".

User Nick Nelson
by
7.9k points