Which code fragment prints Hello World?

Given the code fragment: Which code fragment prints Hello World?

Given the code fragment: Which code fragment prints Hello World?

A.
sb.insert(0,”Hello “); System.out.println(sb);

B.
sb.append(0,”Hello “); System.out.println(sb);

C.
sb.add(0,”Hello “); System.out.println(sb);

D.
sb.set(0,”Hello “); System.out.println(sb);D

Explanation:



Leave a Reply 2

Your email address will not be published. Required fields are marked *


renko

renko

Answer A:

Code question:
public class Main {

public static void main(String[] args) {
StringBuilder sb = new StringBuilder() ;
sb.append (“world”);
//insert code here:
sb.insert(0, “Hello “); //A:
System.out.println(sb);
//sb.append(0, “Hello “); //B:
//System.out.println(sb);
//sb.add(0, “Hello “); //C:
//System.out.println(sb);
//sb.set(0, “Hello “); //C:
//System.out.println(sb);D
}

}
Output:
Hello world