3.4k views
3 votes
Assuming that x = 2 and y = 3, what does the following statement display? System.out.println("%d = %d%n", (x + y), (y + x));

a) %d = %d
b) 5 = 5
c) 5 = %d
d) %d = 5

User Syon
by
7.7k points

1 Answer

3 votes

Final answer:

The statement System.out.println("%d = %d%n", (x + y), (y + x)); would display 5 = 5 when x = 2 and y = 3.

Step-by-step explanation:

The statement System.out.println("%d = %d%n", (x + y), (y + x)); would display 5 = 5 when x = 2 and y = 3.

Let's break down the statement:

  1. The format string "%d = %d%n" specifies that the first %d will be replaced by the sum of x and y, and the second %d will be replaced by the sum of y and x.
  2. Hence, (x + y) = 2 + 3 = 5 and (y + x) = 3 + 2 = 5.
  3. When the statement is printed, %d is replaced by the respective values, resulting in 5 = 5.

User Raed Alahmad
by
7.9k points