Menu
Question Index
...

What will be the output of the following program?

public class StringBufferDemo {
    public static void main(String[] args) {
        StringBuffer givenString = new StringBuffer("Now you are attempting CountCharacters program. Thank you.");
        int count = 0;
        for (int i = 0; i < givenString.length(); i++) {
            if (givenString.charAt(i) == 't' || givenString.charAt(i) == 'T') {
                count++;
                givenString.setCharAt(i, '_');
            }
        }
        System.out.println("Found " + count + " t's in the givenString.");
        System.out.println(givenString);
    }
}


Found 6 t's in the givenString.
Now you are a__emp_ing Coun_Charac_ers program._hank you.
Found 6 t's in the givenString.
Now you are at_emp_ing Coun_Charac_ers program. _hank you.
Found 6 t's in the givenString.
Now you are attempting CountCharacters program. Thank you.
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java charAt() And setCharAt() Methods in StringBuffer

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App