nerdexam
Oracle

1Z0-803 · Question #76

Given the code fragment: String name = "Spot"; int age = 4; String str ="My dog " + name + " is " + age; System.out.println(str); And StringBuilder sb = new StringBuilder(); Using StringBuilder, which

The correct answer is A. sb.append("My dog " + name + " is " + age); D. sb.append("My dog ").append( name ).append(" is. If there is sinle choice question in the real exam, only D is right.

Working with Selected Classes from the Java API

Question

Given the code fragment:

String name = "Spot"; int age = 4; String str ="My dog " + name + " is " + age; System.out.println(str); And StringBuilder sb = new StringBuilder(); Using StringBuilder, which code fragment is the best potion to build and print the following string My dog Spot is 4

Options

  • Asb.append("My dog " + name + " is " + age);
  • Bsb.insert("My dog ").append( name + " is " + age);
  • Csb.insert("My dog ").insert( name ).insert(" is
  • Dsb.append("My dog ").append( name ).append(" is

How the community answered

(48 responses)
  • A
    85% (41)
  • B
    4% (2)
  • C
    10% (5)

Explanation

If there is sinle choice question in the real exam, only D is right.

Topics

#StringBuilder#string concatenation#Java API

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice