Menu
Question Index
...

What will be the output of the following program?

public class DaVinciCode {

    static String code = "";
    static int decrement = 1;

    public static void main(String[] args) {
        code = "Mona";
        wrap('(');
        reverse();
        wrap('{');
        code += "Lisa";
        reverse();
        decrement--;
        wrap('[');
        System.out.println(reverse());
    }

    public static void wrap(char c) {
        code = c + code + (char) (c + decrement);
    }

    public static String reverse() {
        String result = code;
        code = new StringBuffer(result).reverse().toString();
        decrement++;
        return result;
    }
}


[{(Mona)}Lisa]
[asiL|(Mona){\
[asiL}(Mona){]
[asiL})anoM({]
Some other output or Compilation Error

Doubts

Problems

Topic: Java StringBuffer, reverse() - Reverse A String 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