Menu
Topics Index
...
`

setCharAt


If you need explanation Read this topic

If you need Answer Take test on this topic

setCharAt
What will be the output of the following program?
public class TomAndJerry {
    public static void main(String[] args) {
        String tom = "cat";
        StringBuffer jerry = new StringBuffer(tom);
        System.out.print(jerry);
        jerry.setCharAt(0, r);
        System.out.print(" " + jerry);
    }
}

A. cat cat
B. cat rat
C. Compilation Error
D. Runtime Error
Topic: Java charAt() And setCharAt() Methods in StringBuffer

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is B.. 0th char updated to r.. first prints cat and then rat

Posted by Om Prakash Om    2014-01-31 04:03:41


Ans is C, In setCharAt() " r " is must be character.. so it should be like 'r' in single quotes. here r treated as variable .

Posted by Mallikarjuna Rao    2014-01-31 05:29:48


Ans is b.

Posted by Lavanya Kategaru    2014-01-31 08:22:38


Ans is C

Posted by Kick Bhasha    2014-01-31 11:55:32


Congratulations Mallikarjuna Rao. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-02-03 04:35:11


© meritcampus 2019

All Rights Reserved.

Open In App