Menu
Question Index
...

What will be the output of the following program?

public class Console {
    public static void main(String[] arg) {
        int total = 0;
        StringBuffer input = new StringBuffer("supmactirem");
        input.trimToSize();
        String str = input.reverse().toString();
        System.out.println(str);
        System.out.println(input.reverse().toString());
        for (int i = 0; i < str.length(); i++) {
            total += str.codePointAt(i++);
            str = str.substring(i);
        }
        System.out.println(str);
        System.out.print("Total " + total);
    }
}


meritcampus
supmactirem
meritcampus
Total 326
meritcampus
meritcampus
meritcampus
Total 334
meritcampus
meritcampus
meritcampus
Total 527
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Additional StringBuffer Methods In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App