Tag Archives: quotMy

Given the code fragment: String name = "Spot"; int age = 4; String str ="My dog " + name + " is " + age;

Given the code fragment:String name = “Spot”;int age = 4;String str =”My dog ” + name + ” is ” + age;System.out.println(str);AndStringBuilder sb = new StringBuilder();Using StringBuilder, which code fragment is the best potion to build and print the followingstring My dog Spot is 4 A. sb.append(“My dog “).append( name ).append(” is ” ).append(age); System.out.println(sb); B. sb.insert(“My dog… Read More »