Return to site

JAVA CERTIFICATION QUESTION: Text blocks and the string indent method in Java

· java

Text blocks ease programming long string literals, but you need to know the details.

Given the code fragment:

var s = """
◌◌A
◌◌◌\
◌◌◌◌\s
◌◌◌◌◌B""";
s = s.indent(-2); // line n1
s = s.indent(-2); // line n2
System.out.println("---");
System.out.println(s);
System.out.println("---");

 

Assuming that the following character: ◌ denotes whitespace characters, what is the result? Choose one.

A) Runtime exception at line n2

 

B)

---

A

◌◌

◌◌◌B

---

 

C)

---

A

 

◌B

---

 

D)

---

A

 

 

---

 

 

 

 

 

 

·ꓷ uoᴉʇdo sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ ·uoᴉsnʅɔuoꓛ